Submission #15484092


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];
    bitset<30> b(vec[i]);
    for(int j=0; j<30; j++){
      if(b.test(j)){
        mp[j]++;
        break;
      }
    }
  }
  
  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)){
      if(mp.count(i)){
        ans++;
        for(int j=0; j<=i; j++){
          B.flip(j);
        }
      }
      else{
        flag = false;
      }
    }
  }
  
  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 500
Code Size 793 Byte
Status
Exec Time 50 ms
Memory 4052 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 7 ms 3432 KB
001.txt 2 ms 3520 KB
002.txt 41 ms 4048 KB
003.txt 22 ms 3632 KB
004.txt 22 ms 3524 KB
005.txt 16 ms 3524 KB
006.txt 45 ms 3920 KB
007.txt 40 ms 3872 KB
008.txt 41 ms 3824 KB
009.txt 48 ms 3952 KB
010.txt 46 ms 3952 KB
011.txt 45 ms 3992 KB
012.txt 41 ms 3888 KB
013.txt 41 ms 3816 KB
014.txt 46 ms 3824 KB
015.txt 40 ms 3984 KB
016.txt 45 ms 3892 KB
017.txt 46 ms 4052 KB
018.txt 50 ms 3988 KB
019.txt 46 ms 3896 KB
020.txt 40 ms 3832 KB
021.txt 9 ms 3700 KB
022.txt 9 ms 3572 KB
023.txt 40 ms 4048 KB
example0.txt 5 ms 3416 KB
example1.txt 2 ms 3524 KB