Submission #3728743


Source Code Expand

#include<map>
#include<set>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<chrono>
#include<stack>
#include<fstream>
#include<list>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define SIZE(a) ll(a.size())
#define vll vector<ll> 
#define MEMSET(a, n, m) for(ll i=0;i<=n;i++) a[i] = m
#define BIT(n) (ll(1)<<n)
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end()) 
#define UNIQUE_ARRAY(a,n) n = unique(a + 1, a + x + 1) - a - 1
#define SORT(a,n) sort(a+1,a+n+1)
#define SORT_O(a,n,order) sort(a+1,a+n+1,order)
#define PER(i,y,x) for(ll i=y;i>=x;i--)
typedef long long ll;
using namespace std;


struct point
{
	long long name; long long dist;
bool operator<(const point& rhs) const {
return dist > rhs.dist;
}
};

ll const MAX = 100005;
ll a[MAX], b[MAX] = {};

int main(){
	ll n;
	cin >> n;
	ll x = 0;
	REP(i, 1, n) {
		cin >> a[i];
		x ^= a[i];
	}
	ll ans = 0;
	REP(i, 1, n) {
		ll u = 1;
		ll v = a[i];
		while ((v & 1) == 0) {
			u++;
			v /= 2;
		}
		b[i] = u;
		//cout << i << " " << b[i] << endl;
	}
	while (x > 0) {
		ll y = x;
		ll u = 0;
		while (y > 0) {
			u++;
			y /= 2;
		}
		//cout << x << " ! " << u  << endl;
		bool flag = 1;
		REP(i, 1, n) {
			if (u == b[i]) {
				x ^= a[i];
				x ^= (a[i] - 1);
				//cout << i << " " <<x << endl;
				b[i] = -1;
				ans++;
				flag = 0;
				break;
			}
		}
		if (flag == 1) {
			cout << -1 << endl;
			return 0;
		}
		
	}	
	cout << ans << endl;

}

Submission Info

Submission Time
Task C - Cheating Nim
User nejineji
Language C++14 (GCC 5.4.1)
Score 500
Code Size 1575 Byte
Status AC
Exec Time 45 ms
Memory 1792 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 2
AC × 26
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 45 ms 1792 KB
003.txt AC 15 ms 1152 KB
004.txt AC 16 ms 1024 KB
005.txt AC 13 ms 768 KB
006.txt AC 43 ms 1792 KB
007.txt AC 43 ms 1792 KB
008.txt AC 43 ms 1792 KB
009.txt AC 43 ms 1792 KB
010.txt AC 43 ms 1792 KB
011.txt AC 43 ms 1792 KB
012.txt AC 43 ms 1792 KB
013.txt AC 43 ms 1792 KB
014.txt AC 43 ms 1792 KB
015.txt AC 43 ms 1792 KB
016.txt AC 43 ms 1792 KB
017.txt AC 43 ms 1792 KB
018.txt AC 43 ms 1792 KB
019.txt AC 43 ms 1792 KB
020.txt AC 43 ms 1792 KB
021.txt AC 5 ms 384 KB
022.txt AC 5 ms 384 KB
023.txt AC 43 ms 1792 KB
example0.txt AC 1 ms 256 KB
example1.txt AC 1 ms 256 KB