Submission #2801094
Source Code Expand
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5; const int INF = 1e9; int N; long long A[MAXN + 10]; long long lg(long long 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("%lld", &A[i]); if((A[i] & (A[i] - 1LL)) == 0LL) { cnt[lg(A[i])] = true; } } long long xr = 0; for(int i = 0; i < N; i++) { xr ^= A[i]; } int res = 0; for(long long i = 30; i > 0; i--) { if(xr & (1LL << i)) { if(!cnt[i]) { print("-1\n"); exit(0); } xr ^= 1LL << i; xr ^= (1LL << i) - 1LL; res++; } } int cc = N; for(int i = 0; i < N; i++) { if((A[i] & (A[i] - 1LL)) == 0LL) cc--; } if(xr == 0LL) printf("%d\n", res); else if(xr == 1LL && cc > 0LL) 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 | 1026 Byte |
Status | CE |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:38:25: error: ‘print’ was not declared in this scope print("-1\n"); ^ ./Main.cpp:23:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d", &N); ^ ./Main.cpp:25:27: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%lld", &A[i]); ^