CODE FESTIVAL 2016 Grand Final(Parallel)

Submission #1678306

Source codeソースコード

//------------------------------>> tsukasa_diary's template <<------------------------------//
#include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define for_rev(i,a,b) for(int i=(a);i>=(b);--i)
#define allof(a) (a).begin(),(a).end()
#define minit(a,b) memset(a,b,sizeof(a))

using lint = long long;
using pii = pair< int, int >;

template< typename T > using Vec = vector< T >;

template< typename T > bool in_range(T x, T lb, T ub) { return lb <= x && x < ub; }
template< typename T > bool in_range(T x, T y, T lb, T ub) { return in_range(x, lb, ub) && in_range(y, lb, ub); }

template< typename T > void modAdd(T& a, T b, T mod) { a = (a + b + mod) % mod; }
template< typename T > void modMul(T& a, T b, T mod) { a = (a * b) % mod; }
template< typename T > void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > void maxUpdate(T& a, T b) { a = max(a, b); }

int bitCount(int x) { return __builtin_popcount(x); }
int bitCount(lint x) { return __builtin_popcountll(x); }

const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};
const double EPS = 1e-9;
const double PI = acos(-1);

//--------------8---------------->> coding space <<-----------------8-------------//

int N, a[100005];

int main() {
	cin >> N;
	for_(i,0,N) cin >> a[i];
	
	int xor_sum = 0;
	for_(i,0,N) xor_sum ^= a[i];
	
	int ans = 0;
	for_rev(b,31,0) {
		if (xor_sum >> b & 1) {
			int k = -1;
			for_(i,0,N) {
				if (a[i] == (1 << b)) {
					k = i;
					break;
				}
			}
			
			if (k == -1) {
				puts("-1");
				return 0;
			}
			
			xor_sum ^= a[k];
			a[k]--;
			xor_sum ^= a[k];
			++ans;
		}
	}
	cout << ans << endl;
}
//--------------8---------------->> coding space <<-----------------8-------------//

Submission

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

Test case

Set

Set name Score得点 / Max score Cases
Sample - example0.txt,example1.txt
All 0 / 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 WA
001.txt AC 1 ms 256 KB
002.txt AC 44 ms 640 KB
003.txt AC 14 ms 512 KB
004.txt AC 16 ms 384 KB
005.txt AC 13 ms 384 KB
006.txt WA
007.txt WA
008.txt WA
009.txt WA
010.txt WA
011.txt WA
012.txt WA
013.txt WA
014.txt WA
015.txt WA
016.txt AC 41 ms 640 KB
017.txt AC 40 ms 640 KB
018.txt WA
019.txt WA
020.txt AC 40 ms 640 KB
021.txt AC 5 ms 256 KB
022.txt AC 5 ms 256 KB
023.txt AC 40 ms 640 KB
example0.txt AC 1 ms 256 KB
example1.txt AC 1 ms 256 KB