1915E - Romantic Glasses - CodeForces Solution


data structures greedy math

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define si set<int>
#define sll set<ll>
#define sch set<char>
#define msi multiset<int>
#define msll multiset<ll>
#define vll vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vb vector<bool>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vpii vector<pair<int,int>>
#define vpic vector<pair<int, char>>
#define sti  stack<int> 
#define stc  stack<char>
#define forarr(n,a) for(int i=0;i<n;i++) cin>>a[i];
const ll M=1e9+7;
ll fact(int n){
    ll ans=1;
    for(int i=1;i<=n;i++) ans*=i;
    return ans;
}
ll NCR(int n,int r){
    return fact(n)/(fact(r)*(fact(n-r)));
}
ll GCD(ll a,ll b){
    if(a==0) return b;
    return GCD(b%a,a);
}
void solve(){
    ll n;
    cin>>n;
    vll a(n);
    forarr(n,a);
    ll sum=0;
    sll s;
    s.insert(0);
    for(int i=0;i<n;i++){
        if(i%2==0){
            sum+=a[i];
            if(s.count(sum)){
                cout<<"YES\n";
                return;
            }
            else s.insert(sum);
        }
        else{
            sum-=a[i];
            if(s.count(sum)){
                cout<<"YES\n";
                return;
            }
            else s.insert(sum);
        }
    }
    cout<<"NO\n";
}
int main(){
    ll tc;
    cin >> tc;
    //tc=1;
    while(tc--){
        solve();
    }
}


Comments

Submit
0 Comments
More Questions

466C - Number of Ways
1146A - Love "A"
1618D - Array and Operations
1255A - Changing Volume
1710C - XOR Triangle
415C - Mashmokh and Numbers
8A - Train and Peter
591A - Wizards' Duel
1703G - Good Key Bad Key
1705A - Mark the Photographer
1707A - Doremy's IQ
1706B - Making Towers
1325B - CopyCopyCopyCopyCopy
1649C - Weird Sum
1324B - Yet Another Palindrome Problem
525A - Vitaliy and Pie
879A - Borya's Diagnosis
1672B - I love AAAB
1673A - Subtle Substring Subtraction
1345A - Puzzle Pieces
711A - Bus to Udayland
779B - Weird Rounding
1703D - Double Strings
1704C - Virus
63A - Sinking Ship
1704B - Luke is a Foodie
298B - Sail
239A - Two Bags of Potatoes
1704E - Count Seconds
682A - Alyona and Numbers