Submission #15483832


Source Code Expand

Copy
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t N;
  cin >> N;
  vector<int64_t> vec(N);
  map<int64_t,int64_t> mp;
  for(int i=0; i<N; i++){
    cin >> vec[i];
    mp[vec[i]]++;
  }
  int64_t sum = 0;
  for(int i=0; i<N; i++){
    sum ^= vec[i];
  }
  
  bool flag = true;
  int64_t ans = 0;
  
  bitset<30> B(sum);
  for(int i=29; i>0; i--){
    if(B.test(i)){
      int64_t a = pow(2,i);
      if(mp.count(a)){
        B.reset(i);
        ans++;
        for(int j=0; j<i; j++){
          B.flip(j);
        }
      }
      else{
        flag = false;
      }
    }
  }
  
  if(B.test(0)){
    if(ans == N){
      flag = false;
    }
    else{
      ans++;
    }
  }
  
  if(!flag){
    cout << -1 << endl;
  }
  else{
    cout << ans << endl;
  }
          
}

Submission Info

Submission Time
Task C - Cheating Nim
User myau
Language C++ (GCC 9.2.1)
Score 0
Code Size 833 Byte
Status
Exec Time 71 ms
Memory 7972 KB

Judge Result

Set Name Score / Max Score Test Cases
Sample 0 / 0 example0.txt, example1.txt
All 0 / 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 3772 KB
001.txt 5 ms 3972 KB
002.txt 42 ms 3884 KB
003.txt 19 ms 3852 KB
004.txt 36 ms 6880 KB
005.txt 23 ms 5760 KB
006.txt 67 ms 7696 KB
007.txt 65 ms 7580 KB
008.txt 71 ms 7556 KB
009.txt 59 ms 7744 KB
010.txt 69 ms 7672 KB
011.txt 69 ms 7632 KB
012.txt 61 ms 7516 KB
013.txt 63 ms 7600 KB
014.txt 61 ms 7604 KB
015.txt 61 ms 7744 KB
016.txt 64 ms 7628 KB
017.txt 69 ms 7924 KB
018.txt 65 ms 7848 KB
019.txt 63 ms 7744 KB
020.txt 68 ms 7972 KB
021.txt 12 ms 4548 KB
022.txt 20 ms 4416 KB
023.txt 48 ms 3804 KB
example0.txt 7 ms 3668 KB
example1.txt 2 ms 3788 KB