1669C - OddEven Increments - CodeForces Solution


greedy greedy implementation math *800

Please click on ads to support us..

C++ Code:

// codex by priyanshu
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fast()                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)
#define loop(i, ini, n) for (ll i = ini; i < (ll)n; i++)
#define pool(i, n, last) for (ll i = (ll)n; i > last; i--)
#define all(x) x.begin(), x.end()
#define tc     \
    ll tt;     \
    cin >> tt; \
    while (tt--)
#define gcd __gcd
#define inf 1e18
#define ninf INT_MIN
#define pb push_back
#define po pop_back
#define sz size()
#define ed end()
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define vl vector<ll>
#define vll vector<vector<ll>>
#define pl pair<ll, ll>
#define ml map<ll, ll>
#define sl set<ll>
#define ql queue<ll>
const int N = 1000001;
#define pi 3.1415926536
ll mod = 32768;

void solve()
{
    ll n;
    cin>>n;
     vl v(n);
     ll sum=0;
     loop(i,0,n) cin>>v[i], sum+=v[i];
    
    sl s1, s2;
    for(int i=0; i<n; i+=2){
        s1.insert(v[i]%2);
    }
    for(int i=1; i<n; i+=2){
        s2.insert(v[i]%2);
    }

    if(s1.size()==1 && s2.size()==1) cout<<"YES\n";
    else cout<<"NO\n";
}

int main()
{
    fast();
    tc
    {
        solve();
    }
}


Comments

Submit
0 Comments
More Questions

779. K-th Symbol in Grammar
701. Insert into a Binary Search Tree
429. N-ary Tree Level Order Traversal
739. Daily Temperatures
647. Palindromic Substrings
583. Delete Operation for Two Strings
518. Coin Change 2
516. Longest Palindromic Subsequence
468. Validate IP Address
450. Delete Node in a BST
445. Add Two Numbers II
442. Find All Duplicates in an Array
437. Path Sum III
436. Find Right Interval
435. Non-overlapping Intervals
406. Queue Reconstruction by Height
380. Insert Delete GetRandom O(1)
332. Reconstruct Itinerary
368. Largest Divisible Subset
377. Combination Sum IV
322. Coin Change
307. Range Sum Query - Mutable
287. Find the Duplicate Number
279. Perfect Squares
275. H-Index II
274. H-Index
260. Single Number III
240. Search a 2D Matrix II
238. Product of Array Except Self
229. Majority Element II