CODE FESTIVAL 2016 Grand Final(Parallel)

Submission #1247851

Source codeソースコード

#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

Task問題 C - Cheating Nim
User nameユーザ名 vjudge1
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 500
Source lengthソースコード長 1660 Byte
File nameファイル名
Exec time実行時間 46 ms
Memory usageメモリ使用量 1792 KB

Test case

Set

Set name Score得点 / Max score Cases
Sample - example0.txt,example1.txt
All 500 / 500 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

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
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