Submission #15230952


Source Code Expand

Copy
/* Author : Aaryan Srivastava ^__^ */ 
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back   
#define sz(a) ((int)a.size())
using namespace std;
typedef long long ll ; 
const ll inf = 1e18 ;
const int mod = 1e9 + 7;
const int N = 3e5 + 5; 
const int SZ = 101;
ll po(ll x,ll y,ll p = mod) {ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}

int lg2(int x){
    int cnt = -1;
    while(x) cnt++ , x >>= 1; 
    return cnt ;
}

void solve(){
    int n ;
    ll t = 0;
    cin >> n ;
    bool v[50] = {};
    for(int i = 0 ; i < n ; ++i){
        ll x ;
        cin >> x;
        t ^= x ;
        x ^= (x - 1);
        v[lg2(x + 1) - 1] = true ;
    }
    bitset<60> bset(t);
    int tmp = 59 , cnt = 0;
    bool ans = true ;
    while(tmp >= 0){        
        while(tmp >= 0 && !bset[tmp]) --tmp;
        if(tmp < 0) break ;
        ans &= (v[tmp]);
        cnt++;
        while(tmp >= 0 && bset[tmp]) --tmp;
        if(tmp < 0) break ;
        ans &= (v[tmp]);        
        cnt++;
    }
    cout << (ans ?  cnt : -1);

}

int main()
{
    ios::sync_with_stdio(false); cout.tie(NULL); cin.tie(NULL);
    int TC = 1, t = 0;
    // cin >> TC ;
    while(t++ < TC)
    {
        // cout << "Case #" << t << ": " ;
        solve();
        cout << "\n" ;
    }
    return 0;
}

Submission Info

Submission Time
Task C - Cheating Nim
User deathliger
Language C++ (GCC 9.2.1)
Score 500
Code Size 1391 Byte
Status
Exec Time 27 ms
Memory 3656 KB

Judge Result

Set Name Score / Max Score Test Cases
Sample 0 / 0 example0.txt, example1.txt
All 500 / 500 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, example0.txt, example1.txt
Case Name Status Exec Time Memory
000.txt 8 ms 3536 KB
001.txt 3 ms 3596 KB
002.txt 13 ms 3656 KB
003.txt 7 ms 3604 KB
004.txt 13 ms 3544 KB
005.txt 7 ms 3620 KB
006.txt 16 ms 3612 KB
007.txt 15 ms 3608 KB
008.txt 24 ms 3612 KB
009.txt 16 ms 3536 KB
010.txt 16 ms 3616 KB
011.txt 17 ms 3488 KB
012.txt 19 ms 3584 KB
013.txt 21 ms 3656 KB
014.txt 20 ms 3540 KB
015.txt 19 ms 3524 KB
016.txt 27 ms 3640 KB
017.txt 15 ms 3544 KB
018.txt 18 ms 3544 KB
019.txt 23 ms 3520 KB
020.txt 21 ms 3520 KB
021.txt 4 ms 3544 KB
022.txt 4 ms 3640 KB
023.txt 19 ms 3532 KB
example0.txt 2 ms 3636 KB
example1.txt 2 ms 3476 KB