結果
| 問題 |
No.2165 Let's Play Nim!
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2022-12-19 01:40:02 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,533 bytes |
| コンパイル時間 | 631 ms |
| コンパイル使用メモリ | 61,104 KB |
| 実行使用メモリ | 40,628 KB |
| 平均クエリ数 | 623.05 |
| 最終ジャッジ日時 | 2024-11-18 00:11:35 |
| 合計ジャッジ時間 | 37,958 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 7 WA * 23 RE * 5 TLE * 3 |
ソースコード
/* -*- coding: utf-8 -*-
*
* 2165.cc: No.2165 Let's Play Nim! - yukicoder
*/
#include<cstdio>
#include<set>
#include<algorithm>
#include<utility>
#include<functional>
using namespace std;
/* constant */
const int MAX_N = 75000;
const int BN = 17;
enum { First = 1, Second = 0 };
/* typedef */
typedef pair<int,int> pii;
typedef set<pii> spii;
/* global variables */
int as[MAX_N];
spii bps[BN];
/* subroutines */
inline int msb(int x) {
int k = 0, bk = 1;
while ((bk << 1) <= x) k++, bk <<= 1;
//printf("msb(%d)=%d\n", x, k);
return k;
}
void replace(int i, int ai) {
bps[msb(as[i])].erase(pii(as[i], i));
if (ai > 0) bps[msb(ai)].insert(pii(ai, i));
as[i] = ai;
}
int my_act(int x) {
int i = bps[msb(x)].begin()->second;
int ai = x ^ as[i], k = as[i] - ai;
replace(i, ai);
printf("%d %d\n", i + 1, k); fflush(stdout);
int r;
scanf("%d", &r);
return r;
}
int judge_act() {
int i, k, r;
scanf("%d%d%d", &i, &k, &r), i--;
int ai = as[i] - k, x = as[i] ^ ai;
replace(i, ai);
return (r < 0) ? -1 : x;
}
/* main */
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", as + i);
int x = 0;
for (int i = 0; i < n; i++) {
x ^= as[i];
bps[msb(as[i])].insert(pii(as[i], i));
}
if (x != 0) {
printf("%d\n", First), fflush(stdout);
my_act(x);
}
else
printf("%d\n", Second), fflush(stdout);
for (;;) {
int x = judge_act();
if (x < 0) break;
int r = my_act(x);
if (r < 0) break;
}
return 0;
}
tnakao0123