Submission #1247851


Source Code Expand

#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>

using namespace std;
typedef long long int LL;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

int xcomp(vector<LL>& a, vector<LL>& b) {
	return a[0] < b[0];
}

#define XSORT(c) sort((c).begin(),(c).end(),xcomp)

#define ALL(x) (x).begin(),(x).end()
LL mod = 1000000007;

LL pow2(LL x) {
	if (x == 0) {
		return 1;
	}
	else {
		return pow2(x - 1) * 2;
	}
}

LL ketasu(LL x) {
	if (x == 1) {
		return 1;
	}else
		if (x == 0) {
			return 0;
		}
		else {
			return ketasu(x / 2) + 1;
		}
}

int main() {
	LL N;
	cin >> N;
	LL vv = 0;
	vector<LL> v(N, 0);
	vector<LL> h(N, 0);
	vector<LL> ni(30, 0);
	REP(i, N) {
		cin >> v[i];
		h[i] = v[i] ^ (v[i] - 1); 
		ni[ketasu(h[i])] = 1;
		vv = vv^v[i];
	}
	LL sum=0;
	while (true) {
		if (vv == 0) {
			cout<< sum<<endl;
			break;
		}
		if (ni[ketasu(vv)] == 1) {
			vv = vv ^ (pow2(ketasu(vv)) - 1);
			sum++;
		}
		else {
			cout << -1 << endl;
			break;
		}
	}
}

Submission Info

Submission Time
Task C - Cheating Nim
User vjudge1
Language C++14 (GCC 5.4.1)
Score 500
Code Size 1660 Byte
Status AC
Exec Time 46 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 44 ms 1792 KB
009.txt AC 43 ms 1792 KB
010.txt AC 46 ms 1792 KB
011.txt AC 43 ms 1792 KB
012.txt AC 44 ms 1792 KB
013.txt AC 43 ms 1792 KB
014.txt AC 43 ms 1792 KB
015.txt AC 44 ms 1792 KB
016.txt AC 43 ms 1792 KB
017.txt AC 43 ms 1792 KB
018.txt AC 46 ms 1792 KB
019.txt AC 44 ms 1792 KB
020.txt AC 44 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