Submission #15483811


Source Code Expand

Copy
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> vec(N);
  map<int,int> mp;
  for(int i=0; i<N; i++){
    cin >> vec[i];
    mp[vec[i]]++;
  }
  int sum = 0;
  for(int i=0; i<N; i++){
    sum ^= vec[i];
  }
  
  bool flag = true;
  int ans = 0;
  
  bitset<30> B(sum);
  for(int i=29; i>0; i--){
    if(B.test(i)){
      int 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 805 Byte
Status
Exec Time 64 ms
Memory 6704 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 3480 KB
001.txt 2 ms 3792 KB
002.txt 45 ms 3788 KB
003.txt 29 ms 4092 KB
004.txt 38 ms 6060 KB
005.txt 30 ms 5520 KB
006.txt 62 ms 6556 KB
007.txt 56 ms 6560 KB
008.txt 63 ms 6704 KB
009.txt 64 ms 6524 KB
010.txt 61 ms 6656 KB
011.txt 64 ms 6644 KB
012.txt 62 ms 6596 KB
013.txt 63 ms 6520 KB
014.txt 64 ms 6644 KB
015.txt 61 ms 6652 KB
016.txt 56 ms 6532 KB
017.txt 59 ms 6648 KB
018.txt 61 ms 6692 KB
019.txt 62 ms 6540 KB
020.txt 63 ms 6572 KB
021.txt 13 ms 4244 KB
022.txt 14 ms 4300 KB
023.txt 39 ms 3832 KB
example0.txt 4 ms 3540 KB
example1.txt 2 ms 3940 KB