結果

問題 No.2165 Let's Play Nim!
ユーザー norikamenorikame
提出日時 2022-12-16 13:08:03
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 202 ms / 2,000 ms
コード長 1,771 bytes
コンパイル時間 4,347 ms
コンパイル使用メモリ 265,548 KB
実行使用メモリ 24,408 KB
平均クエリ数 894.18
最終ジャッジ日時 2023-08-09 20:49:47
合計ジャッジ時間 22,511 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
23,436 KB
testcase_01 AC 135 ms
23,520 KB
testcase_02 AC 145 ms
23,436 KB
testcase_03 AC 98 ms
23,436 KB
testcase_04 AC 27 ms
23,556 KB
testcase_05 AC 32 ms
23,532 KB
testcase_06 AC 32 ms
24,348 KB
testcase_07 AC 32 ms
24,048 KB
testcase_08 AC 102 ms
23,532 KB
testcase_09 AC 27 ms
23,820 KB
testcase_10 AC 37 ms
24,300 KB
testcase_11 AC 148 ms
23,412 KB
testcase_12 AC 129 ms
24,084 KB
testcase_13 AC 25 ms
24,024 KB
testcase_14 AC 30 ms
23,364 KB
testcase_15 AC 26 ms
24,300 KB
testcase_16 AC 118 ms
24,372 KB
testcase_17 AC 67 ms
23,400 KB
testcase_18 AC 202 ms
23,436 KB
testcase_19 AC 26 ms
24,060 KB
testcase_20 AC 30 ms
23,820 KB
testcase_21 AC 55 ms
23,436 KB
testcase_22 AC 46 ms
23,676 KB
testcase_23 AC 45 ms
23,400 KB
testcase_24 AC 41 ms
24,096 KB
testcase_25 AC 82 ms
23,364 KB
testcase_26 AC 147 ms
23,616 KB
testcase_27 AC 50 ms
23,436 KB
testcase_28 AC 74 ms
23,412 KB
testcase_29 AC 25 ms
23,424 KB
testcase_30 AC 25 ms
24,408 KB
testcase_31 AC 25 ms
23,340 KB
testcase_32 AC 70 ms
23,580 KB
evil_2_big_1.txt AC 1,587 ms
24,432 KB
evil_2_big_2.txt TLE -
evil_2_big_3.txt AC 1,554 ms
24,024 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() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> 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;
	cout << ti << endl;
	cout.flush();
	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;
		cout << (id+1) << ' ' << ki << endl;
		cout.flush();
		cin >> ret;
	}
	while (ret != -1) {
		int id2, ki2;
		cin >> 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>());
		cin >> 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;
		cout << (id+1) << ' ' << ki << endl;
		cout.flush();
		cin >> ret;
	}
	return 0;
}
0