結果

問題 No.2165 Let's Play Nim!
ユーザー 👑 kmjpkmjp
提出日時 2022-12-17 01:02:02
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 189 ms / 2,000 ms
コード長 1,503 bytes
コンパイル時間 2,083 ms
コンパイル使用メモリ 206,500 KB
実行使用メモリ 24,468 KB
平均クエリ数 863.56
最終ジャッジ日時 2023-08-10 06:17:37
合計ジャッジ時間 17,483 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
24,072 KB
testcase_01 AC 124 ms
23,568 KB
testcase_02 AC 137 ms
24,360 KB
testcase_03 AC 90 ms
23,280 KB
testcase_04 AC 25 ms
23,568 KB
testcase_05 AC 31 ms
23,424 KB
testcase_06 AC 30 ms
24,420 KB
testcase_07 AC 29 ms
23,412 KB
testcase_08 AC 96 ms
23,568 KB
testcase_09 AC 27 ms
23,412 KB
testcase_10 AC 31 ms
23,688 KB
testcase_11 AC 141 ms
24,060 KB
testcase_12 AC 126 ms
23,652 KB
testcase_13 AC 26 ms
24,468 KB
testcase_14 AC 31 ms
24,072 KB
testcase_15 AC 28 ms
23,628 KB
testcase_16 AC 118 ms
23,652 KB
testcase_17 AC 62 ms
24,384 KB
testcase_18 AC 189 ms
24,084 KB
testcase_19 AC 25 ms
23,688 KB
testcase_20 AC 27 ms
24,084 KB
testcase_21 AC 54 ms
23,868 KB
testcase_22 AC 41 ms
24,432 KB
testcase_23 AC 38 ms
24,072 KB
testcase_24 AC 37 ms
23,412 KB
testcase_25 AC 78 ms
23,400 KB
testcase_26 AC 138 ms
23,700 KB
testcase_27 AC 48 ms
23,568 KB
testcase_28 AC 71 ms
24,372 KB
testcase_29 AC 25 ms
24,060 KB
testcase_30 AC 24 ms
23,556 KB
testcase_31 AC 23 ms
24,456 KB
testcase_32 AC 91 ms
24,312 KB
evil_2_big_1.txt AC 1,577 ms
24,384 KB
evil_2_big_2.txt AC 1,725 ms
24,432 KB
evil_2_big_3.txt AC 1,559 ms
23,448 KB
evil_big_1.txt AC 1,781 ms
23,868 KB
evil_big_2.txt AC 1,778 ms
24,324 KB
evil_big_3.txt AC 1,819 ms
23,412 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------


int N;
int A[101010];
set<int> S[31];
int nim;

void update(int i,int d) {
	int x;
	FOR(x,30) S[x].erase(i);

	nim^=A[i];
	A[i]-=d;
	nim^=A[i];
	FOR(x,30) if(A[i]&(1<<x)) S[x].insert(i);
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) {
		cin>>A[i];
		nim^=A[i];
		FOR(x,30) if(A[i]&(1<<x)) S[x].insert(i);
	}
	
	if(nim==0) {
		cout<<0<<endl;
		cin>>x>>y;
		update(x-1,y);
		cin>>x;
		if(x==-1) return;
	}
	else {
		cout<<1<<endl;
	}
	
	while(1) {
		x=0;
		while(2<<x<=nim) x++;
		y=*S[x].begin();
		k=A[y]-(nim^A[y]);
		update(y,k);
		assert(nim==0);
		cout<<y+1<<" "<<k<<endl;
		cin>>x;
		if(x==-1) return;
		cin>>x>>y;
		update(x-1,y);
		cin>>x;
		if(x==-1) return;
		
		
	}
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0