結果

問題 No.2165 Let's Play Nim!
ユーザー norikame
提出日時 2022-12-16 13:22:06
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 233 ms / 2,000 ms
コード長 1,804 bytes
コンパイル時間 4,073 ms
コンパイル使用メモリ 256,992 KB
最終ジャッジ日時 2025-02-09 14:18:29
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 34 TLE * 4
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:23:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   23 |         scanf("%d", &n);
      |         ~~~~~^~~~~~~~~~
main.cpp:25:24: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   25 |         rep(i, n) scanf("%d", &a[i]);
      |                   ~~~~~^~~~~~~~~~~~~
main.cpp:41:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   41 |                 scanf("%d", &ret);
      |                 ~~~~~^~~~~~~~~~~~
main.cpp:45:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   45 |                 scanf("%d%d", &id2, &ki2);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~
main.cpp:54:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   54 |                 scanf("%d", &ret);
      |                 ~~~~~^~~~~~~~~~~~
main.cpp:64:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   64 |                 scanf("%d", &ret);
      |                 ~~~~~^~~~~~~~~~~~

ソースコード

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;
	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