Submission #15566417


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 (mb(s) == mb(p)) 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 500
Code Size 614 Byte
Status
Exec Time 52 ms
Memory 3756 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 6 ms 3556 KB
001.txt 2 ms 3448 KB
002.txt 41 ms 3444 KB
003.txt 25 ms 3384 KB
004.txt 20 ms 3444 KB
005.txt 16 ms 3632 KB
006.txt 48 ms 3756 KB
007.txt 45 ms 3460 KB
008.txt 47 ms 3448 KB
009.txt 44 ms 3364 KB
010.txt 49 ms 3448 KB
011.txt 51 ms 3364 KB
012.txt 43 ms 3448 KB
013.txt 48 ms 3652 KB
014.txt 50 ms 3444 KB
015.txt 41 ms 3384 KB
016.txt 49 ms 3712 KB
017.txt 45 ms 3448 KB
018.txt 52 ms 3748 KB
019.txt 51 ms 3372 KB
020.txt 44 ms 3752 KB
021.txt 8 ms 3608 KB
022.txt 8 ms 3504 KB
023.txt 45 ms 3712 KB
example0.txt 2 ms 3464 KB
example1.txt 7 ms 3516 KB