Submission #1001377
Source Code Expand
#include <bits/stdc++.h> using namespace std; int n, a[100009], b[100009]; int main() { scanf("%d", &n); for(int i = 0; i < n; i++) scanf("%d", &a[i]); bool flag = true; for(int i = 30; i >= 0 && flag; i--) { int s = 0; for(int j = 0; j < n; j++) s ^= (a[j] >> i) & 1; if(s == 1) { bool ok = false; for(int j = 0; j < n && !ok; j++) { if(!b[j] && a[j] >> i << i == a[j]) { a[j]--; b[j] = 1; ok = true; } } if(!ok) flag = false; } } int ss = 0; for(int i = 0; i < n; i++) ss ^= a[j]; if(ss != 0) flag = false; if(!flag) printf("-1\n"); else { int ret = 0; for(int i = 0; i < n; i++) ret += b[i]; printf("%d\n", ret); } }
Submission Info
Submission Time | |
---|---|
Task | C - Cheating Nim |
User | square1001 |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 710 Byte |
Status | CE |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:24:37: error: ‘j’ was not declared in this scope for(int i = 0; i < n; i++) ss ^= a[j]; ^ ./Main.cpp:5:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d", &n); ^ ./Main.cpp:6:47: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] for(int i = 0; i < n; i++) scanf("%d", &a[i]); ^