結果

問題 No.2165 Let's Play Nim!
ユーザー 👑 rin204rin204
提出日時 2022-12-16 00:25:39
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 204 ms / 2,000 ms
コード長 1,341 bytes
コンパイル時間 2,255 ms
コンパイル使用メモリ 208,776 KB
実行使用メモリ 24,360 KB
平均クエリ数 863.56
最終ジャッジ日時 2023-08-09 09:39:22
合計ジャッジ時間 17,659 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
23,592 KB
testcase_01 AC 133 ms
24,360 KB
testcase_02 AC 147 ms
23,856 KB
testcase_03 AC 92 ms
23,664 KB
testcase_04 AC 26 ms
23,928 KB
testcase_05 AC 31 ms
23,664 KB
testcase_06 AC 31 ms
23,844 KB
testcase_07 AC 29 ms
23,388 KB
testcase_08 AC 95 ms
23,676 KB
testcase_09 AC 28 ms
23,388 KB
testcase_10 AC 34 ms
23,364 KB
testcase_11 AC 146 ms
23,976 KB
testcase_12 AC 121 ms
23,484 KB
testcase_13 AC 24 ms
24,288 KB
testcase_14 AC 29 ms
23,616 KB
testcase_15 AC 25 ms
24,012 KB
testcase_16 AC 116 ms
23,412 KB
testcase_17 AC 65 ms
23,376 KB
testcase_18 AC 204 ms
23,664 KB
testcase_19 AC 25 ms
24,060 KB
testcase_20 AC 30 ms
23,508 KB
testcase_21 AC 54 ms
23,652 KB
testcase_22 AC 45 ms
24,168 KB
testcase_23 AC 43 ms
23,496 KB
testcase_24 AC 39 ms
23,784 KB
testcase_25 AC 80 ms
23,928 KB
testcase_26 AC 140 ms
24,012 KB
testcase_27 AC 48 ms
23,784 KB
testcase_28 AC 69 ms
23,784 KB
testcase_29 AC 25 ms
23,400 KB
testcase_30 AC 24 ms
24,060 KB
testcase_31 AC 23 ms
23,424 KB
testcase_32 AC 94 ms
23,544 KB
evil_2_big_1.txt AC 1,663 ms
23,592 KB
evil_2_big_2.txt AC 1,867 ms
23,364 KB
evil_2_big_3.txt AC 1,665 ms
23,424 KB
evil_big_1.txt AC 1,782 ms
23,988 KB
evil_big_2.txt AC 1,862 ms
23,928 KB
evil_big_3.txt AC 1,856 ms
24,012 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
// #define endl '\n'

int bit_length(int x){
	int c = 1;
	int i = 0;
	while(c <= x){
		i++;
		c *= 2;
	}
	return i;
}

void solve(){
	int n;
	cin >> n;
	vector<int> A(n);
	int x = 0;
	vector<set<int>> se(20, set<int>());
	for(int i = 0; i < n; i++){
		cin >> A[i];
		x ^= A[i];
		for(int j = 0; j < 20; j++){
			if((A[i] >> j) & 1) se[j].insert(i);
		}
	}
	bool turn;
	if(x == 0){
		cout << 0 << endl;
		turn = false;
	}
	else{
		cout << 1 << endl;
		turn = true;
	}
	int ret;
	while(1){
		if(turn){
			assert(x != 0);
			int b = bit_length(x) - 1;
			auto it = se[b].begin();
			int	i = (*it);
			int	a = A[i];
			for(int j = 0; j < 20; j++){
				if((a >> j) & 1) se[j].erase(i);
			}
			int d = a - (a ^ x);
			cout << i + 1 << " " << d << endl;
			cin >> ret;
			if(ret == -1) return;
			a -= d;
			A[i] = a;
			x = 0;
			for(int j = 0; j < 20; j++){
				if((a >> j) & 1) se[j].insert(i);
			}
		}
		else{
			assert(x == 0);
			int i, k;
			cin >> i >> k;
			i--;
			cin >> ret;
			if(ret == -1) return;
			int a = A[i];
			for(int j = 0; j < 20; j++){
				if((a >> j) & 1) se[j].erase(i);
			}
			x ^= a;
			a -= k;
			x ^= a;
			A[i] = a;
			for(int j = 0; j < 20; j++){
				if((a >> j) & 1) se[j].insert(i);
			}
		}
		turn = turn ^ true;
	}
}

int main(){
	solve();
}
0