Submission #15566229


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;

#define mb __builtin_clz
int n, s = 0;
vector<int> v;

int solve();

int main() {
  cin >> n;
  v.resize(n);
  for (auto &p : v) {
    cin >> p;
    s ^= p;
    p = p ^ (p - 1);
  }
  cout << solve() << endl;
  return 0;
}

int solve() {
  if (!s) return 0;
  sort(v.begin(), v.end(), greater<int>());
  vector<int> basis;
  int cnt = 0;
  for (auto &p : v) {
    for (auto b : basis) p = min(p, p ^ b);
    if (p) {
      basis.push_back(p);
      if (p >> (31 - mb(s)) & 1) s ^= p, ++cnt;
    }
    if (!s) return cnt;
  }
  return -1;
}

Submission Info

Submission Time
Task C - Cheating Nim
User m_tsubasa
Language C++ (GCC 9.2.1)
Score 0
Code Size 621 Byte
Status
Exec Time 49 ms
Memory 3800 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 7 ms 3428 KB
001.txt 2 ms 3484 KB
002.txt 44 ms 3704 KB
003.txt 17 ms 3480 KB
004.txt 26 ms 3508 KB
005.txt 16 ms 3752 KB
006.txt 48 ms 3448 KB
007.txt 46 ms 3760 KB
008.txt 48 ms 3428 KB
009.txt 42 ms 3764 KB
010.txt 49 ms 3764 KB
011.txt 43 ms 3508 KB
012.txt 42 ms 3764 KB
013.txt 46 ms 3704 KB
014.txt 47 ms 3504 KB
015.txt 43 ms 3480 KB
016.txt 44 ms 3504 KB
017.txt 41 ms 3708 KB
018.txt 47 ms 3716 KB
019.txt 45 ms 3508 KB
020.txt 42 ms 3760 KB
021.txt 13 ms 3600 KB
022.txt 9 ms 3460 KB
023.txt 45 ms 3800 KB
example0.txt 2 ms 3560 KB
example1.txt 2 ms 3504 KB