Submission #2801061
Source Code Expand
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5; const int INF = 1e9; int N; int A[MAXN + 10]; void done(int xr) { printf("%d\n", xr); exit(0); } int lg(int x) { int cc = 0; while(x > 1) { x >>= 1; cc++; } return cc; } bool cnt[40]; int main() { scanf("%d", &N); for(int i = 0; i < N; i++) { scanf("%d", &A[i]); if((A[i] & (A[i] - 1)) == 0) { cnt[lg(A[i])] = true; //cerr << "cnt[lg(" << A[i] << ") = " << lg(A[i]) << "] = true\n"; } } int xr = 0; for(int i = 0; i < N; i++) { xr ^= A[i]; } int res = 0; for(int i = 30; i > 0; i--) { if(xr & (1 << i)) { if(!cnt[i]) { print("-1\n"); exit(0); } xr ^= 1 << i; xr ^= (1 << i) - 1; res++; } } int cc = N; for(int i = 0; i < N; i++) { if((A[i] & (A[i] - 1)) == 0) cc--; } if(xr == 0) printf("%d\n", res); else if(xr == 1 && cc > 0) printf("%d\n", res+1); else printf("-1\n"); }
Submission Info
Submission Time | |
---|---|
Task | C - Cheating Nim |
User | ruhanhabib39 |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1110 Byte |
Status | CE |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:43:25: error: ‘print’ was not declared in this scope print("-1\n"); ^ ./Main.cpp:27:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d", &N); ^ ./Main.cpp:29:25: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d", &A[i]); ^