結果

問題 No.2165 Let's Play Nim!
ユーザー norikamenorikame
提出日時 2022-12-16 13:23:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 214 ms / 2,000 ms
コード長 1,755 bytes
コンパイル時間 4,766 ms
コンパイル使用メモリ 267,984 KB
実行使用メモリ 25,580 KB
平均クエリ数 894.18
最終ジャッジ日時 2024-04-27 15:31:33
合計ジャッジ時間 20,588 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
24,556 KB
testcase_01 AC 130 ms
25,324 KB
testcase_02 AC 144 ms
24,940 KB
testcase_03 AC 86 ms
25,324 KB
testcase_04 AC 23 ms
25,196 KB
testcase_05 AC 28 ms
24,940 KB
testcase_06 AC 27 ms
24,812 KB
testcase_07 AC 27 ms
24,556 KB
testcase_08 AC 97 ms
24,568 KB
testcase_09 AC 24 ms
25,208 KB
testcase_10 AC 30 ms
24,952 KB
testcase_11 AC 141 ms
24,556 KB
testcase_12 AC 114 ms
25,196 KB
testcase_13 AC 22 ms
24,556 KB
testcase_14 AC 26 ms
25,520 KB
testcase_15 AC 23 ms
25,196 KB
testcase_16 AC 117 ms
24,940 KB
testcase_17 AC 60 ms
25,196 KB
testcase_18 AC 214 ms
24,812 KB
testcase_19 AC 21 ms
25,208 KB
testcase_20 AC 25 ms
25,208 KB
testcase_21 AC 49 ms
25,220 KB
testcase_22 AC 40 ms
25,220 KB
testcase_23 AC 37 ms
24,964 KB
testcase_24 AC 35 ms
24,836 KB
testcase_25 AC 80 ms
25,220 KB
testcase_26 AC 138 ms
24,940 KB
testcase_27 AC 47 ms
24,940 KB
testcase_28 AC 68 ms
24,556 KB
testcase_29 AC 20 ms
24,556 KB
testcase_30 AC 20 ms
25,196 KB
testcase_31 AC 20 ms
25,196 KB
testcase_32 AC 61 ms
25,580 KB
evil_2_big_1.txt AC 1,570 ms
25,580 KB
evil_2_big_2.txt TLE -
evil_2_big_3.txt AC 1,488 ms
25,184 KB
evil_big_1.txt TLE -
evil_big_2.txt TLE -
evil_big_3.txt TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

// 

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

using ll = long long;

#define rep(i, n) for (int i=0; i<(int)(n); ++(i))
#define rep3(i, m, n) for (int i=(m); (i)<(int)(n); ++(i))
#define repr(i, n) for (int i=(int)(n)-1; (i)>=0; --(i))
#define rep3r(i, m, n) for (int i=(int)(n)-1; (i)>=(int)(m); --(i))
#define all(x) (x).begin(), (x).end()

const int INF = (int)(1e9);
const int BLEN = 17;

int main() {
	int n;
	scanf("%d", &n);
	vector<int> a(n);
	rep(i, n) scanf("%d", &a[i]);
	vector<unordered_set<int>> bids(BLEN);
	rep(i, n) rep(j, BLEN) if (a[i]&(1<<j)) bids[j].insert(i);
	int xval = accumulate(all(a), 0, bit_xor<int>()), ti = (xval != 0) ? 1 : 0;
	printf("%d\n", ti);
	fflush(stdout);
	int ret = 0;
	if (ti == 1) {
		int bi = 31 - __builtin_clz(xval), id = *bids[bi].begin(), ki = a[id] - (a[id]^xval);
		rep(i, BLEN) if (xval&(1<<i)) {
			if (bids[i].find(id) != bids[i].end()) bids[i].erase(id);
			else bids[i].insert(id);
		}
		a[id] ^= xval;
		printf("%d %d\n", id+1, ki);
		fflush(stdout);
		scanf("%d", &ret);
	}
	while (ret != -1) {
		int id2, ki2;
		scanf("%d%d", &id2, &ki2);
		--id2;
		int sval = a[id2] ^ (a[id2]-ki2);
		rep(i, BLEN) if (sval&(1<<i)) {
			if (bids[i].find(id2) != bids[i].end()) bids[i].erase(id2);
			else bids[i].insert(id2);
		}
		a[id2] -= ki2;
		xval = accumulate(all(a), 0, bit_xor<int>());
		scanf("%d", &ret);
		if (ret == -1) break;
		int bi = 31 - __builtin_clz(xval), id = *bids[bi].begin(), ki = a[id] - (a[id]^xval);
		rep(i, BLEN) if (xval&(1<<i)) {
			if (bids[i].find(id) != bids[i].end()) bids[i].erase(id);
			else bids[i].insert(id);
		}
		a[id] ^= xval;
		printf("%d %d\n", id+1, ki);
		fflush(stdout);
		scanf("%d", &ret);
	}
	return 0;
}
0