CODE FESTIVAL 2016 Grand Final

Submission #4184414

Source codeソースコード

#include<bits/stdc++.h>
using namespace std;

int n;

vector<int> v;

long long int ans=0;

set<int> mp;

int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		int a;
		scanf("%d",&a);
		v.push_back(a);
		ans^=a;
		mp.insert(a);
	}
	//cout<<ans<<endl;
	int turn=0;
	int ans2=0;
	for(int i=31;i>=0;i--){
		//cout<<i<<" "<<(ans>>i)<<endl;
		int used=-1;
		if((turn^(ans>>i))&1){
			//cout<<"!! "<<i<<endl;
			if(mp.count(1<<i)==0){
				puts("-1");
				return 0;
			}
			ans2++;
			turn^=true;
			used=(1<<i);
		}
		mp.clear();
		int z=(1<<i)-1;
		vector<int> nex;
		for(auto el:v){
			if(used!=el){
				nex.push_back(el&z);
				mp.insert(el&z);
				continue;
			}
			used=-1;
		}
		v=nex;
	}
	cout<<ans2<<endl;
	return 0;
}

Submission

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

Compiler messageコンパイルメッセージ

./Main.cpp: In function ‘int main()’:
./Main.cpp:16:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&a);
^

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 40 ms 1596 KB
003.txt AC 119 ms 1068 KB
004.txt AC 188 ms 3040 KB
005.txt AC 27 ms 1932 KB
006.txt AC 345 ms 4088 KB
007.txt AC 345 ms 4088 KB
008.txt AC 341 ms 4088 KB
009.txt AC 343 ms 4088 KB
010.txt AC 341 ms 4088 KB
011.txt AC 344 ms 4088 KB
012.txt AC 340 ms 4080 KB
013.txt AC 342 ms 4088 KB
014.txt AC 341 ms 4080 KB
015.txt AC 343 ms 4088 KB
016.txt AC 323 ms 3960 KB
017.txt AC 306 ms 4088 KB
018.txt AC 365 ms 4344 KB
019.txt AC 331 ms 3960 KB
020.txt AC 328 ms 4088 KB
021.txt AC 12 ms 768 KB
022.txt AC 9 ms 640 KB
023.txt AC 33 ms 1528 KB
example0.txt AC 1 ms 256 KB
example1.txt AC 1 ms 256 KB