Submission #2409577
Source Code Expand
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>
#include <cctype>
#include <stack>
#include <bitset>
#include <set>
using namespace std;
using ll = long long;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
const ll MOD = 1e9 + 7;
const ll INF = 1 << 30;
const ll INF2 = 9e18;
const double INF3 = 9e14;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
const int tx[8] = { -1,0,1,-1,1,-1,0,1 }, ty[8] = { -1,-1,-1,0,0,1,1,1 };
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define fr first
#define sc second
int main() {
ll n, a, bit[50] = { 0 }, ans = 0, b1 = 0, b0 = 0;
cin >> n;
for (int i = 0;i<n;i++) {
cin >> a;
if (a&(1 << 0))b1++;
else b0++;
for (int j = 0;j <= 29;j++) {
if (a&(1 << j))bit[j]++;
}
}
for (int i = 29;i >= 1;i--) {
if (bit[i] == 0)continue;
if (bit[i] % 2 == 1) {
if (b0 > 0) {
ans++;
b0--;
for (int j = i;j >= 0;j--)bit[j] = (bit[j] + 1) % 2;
}
else {
cout << -1 << endl;
return 0;
}
}
}
if (bit[0] % 2 == 1) {
if (b1 > 0)ans++, bit[0] = 0;
else {
cout << -1 << endl;
return 0;
}
}
for (int i = 0;i <= 29;i++) {
if (bit[i] % 2 == 1) {
cout << -1 << endl;
return 0;
}
}
cout << ans << endl;
}
Submission Info
Submission Time |
|
Task |
C - Cheating Nim |
User |
kakakakaneko |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
1501 Byte |
Status |
WA |
Exec Time |
49 ms |
Memory |
384 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
0 / 500 |
Status |
|
|
Set Name |
Test Cases |
Sample |
example0.txt, example1.txt |
All |
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 |
AC |
1 ms |
256 KB |
001.txt |
AC |
1 ms |
256 KB |
002.txt |
AC |
47 ms |
256 KB |
003.txt |
AC |
18 ms |
256 KB |
004.txt |
WA |
21 ms |
256 KB |
005.txt |
WA |
16 ms |
256 KB |
006.txt |
AC |
49 ms |
256 KB |
007.txt |
AC |
49 ms |
256 KB |
008.txt |
AC |
49 ms |
256 KB |
009.txt |
AC |
49 ms |
256 KB |
010.txt |
AC |
49 ms |
256 KB |
011.txt |
AC |
49 ms |
256 KB |
012.txt |
AC |
49 ms |
256 KB |
013.txt |
AC |
49 ms |
384 KB |
014.txt |
AC |
49 ms |
256 KB |
015.txt |
AC |
49 ms |
256 KB |
016.txt |
WA |
49 ms |
256 KB |
017.txt |
WA |
49 ms |
256 KB |
018.txt |
AC |
49 ms |
256 KB |
019.txt |
AC |
49 ms |
256 KB |
020.txt |
WA |
49 ms |
256 KB |
021.txt |
WA |
6 ms |
256 KB |
022.txt |
AC |
6 ms |
256 KB |
023.txt |
WA |
47 ms |
256 KB |
example0.txt |
AC |
1 ms |
256 KB |
example1.txt |
AC |
1 ms |
256 KB |