Submission #1247853
Source Code Expand
#include "bits/stdc++.h"
#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(i, (v).size()) { cout << v[i]; if (i != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9
const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)///
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
vi v(n);
REP(i, n)cin >> v[i];
vi b(n);
REP(i, n) {
if (v[i] % 2 == 1) {
b[i] = 0;
}
else {
int res = 0;
while (1) {
if (v[i] & 1 << res) {
b[i] = res;
break;
}
res++;
}
}
}
int x = 0;
REP(i, n) {
x ^= v[i];
}
sort(ALL(b));
int p = INF;
int cnt = 0;
RREP(i, 32) {
if (x & 1 << i) {
p = i;
break;
}
}
RREP(i, p + 1) {
if (cnt % 2 == 0 && x&(1 << i)) {
if (binary_search(ALL(b), i)) {
cnt++;
}
else {
cout << -1 << endl;
return 0;
}
}
else if (cnt % 2 == 1 && !(x & (1 << i))) {
if (binary_search(ALL(b), i)) {
cnt++;
}
else {
cout << -1 << endl;
return 0;
}
}
}
cout << cnt << endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
C - Cheating Nim |
User |
vjudge1 |
Language |
C++14 (GCC 5.4.1) |
Score |
500 |
Code Size |
1822 Byte |
Status |
AC |
Exec Time |
986 ms |
Memory |
1024 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
500 / 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 |
986 ms |
1024 KB |
003.txt |
AC |
7 ms |
768 KB |
004.txt |
AC |
7 ms |
640 KB |
005.txt |
AC |
5 ms |
512 KB |
006.txt |
AC |
16 ms |
1024 KB |
007.txt |
AC |
16 ms |
1024 KB |
008.txt |
AC |
16 ms |
1024 KB |
009.txt |
AC |
16 ms |
1024 KB |
010.txt |
AC |
16 ms |
1024 KB |
011.txt |
AC |
16 ms |
1024 KB |
012.txt |
AC |
16 ms |
1024 KB |
013.txt |
AC |
16 ms |
1024 KB |
014.txt |
AC |
17 ms |
1024 KB |
015.txt |
AC |
16 ms |
1024 KB |
016.txt |
AC |
16 ms |
1024 KB |
017.txt |
AC |
16 ms |
1024 KB |
018.txt |
AC |
16 ms |
1024 KB |
019.txt |
AC |
16 ms |
1024 KB |
020.txt |
AC |
16 ms |
1024 KB |
021.txt |
AC |
2 ms |
384 KB |
022.txt |
AC |
3 ms |
384 KB |
023.txt |
AC |
14 ms |
1024 KB |
example0.txt |
AC |
1 ms |
256 KB |
example1.txt |
AC |
1 ms |
256 KB |