結果
| 問題 |
No.2165 Let's Play Nim!
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-12-16 04:32:15 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,242 bytes |
| コンパイル時間 | 1,965 ms |
| コンパイル使用メモリ | 177,196 KB |
| 実行使用メモリ | 25,964 KB |
| 平均クエリ数 | 214.15 |
| 最終ジャッジ日時 | 2024-11-15 09:10:40 |
| 合計ジャッジ時間 | 12,377 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 9 RE * 29 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n, v = 0, p, x, s, M = 18;
cin >> n;
vector<int> a(n);
vector<set<int>> S(M);
for(int i = 0; i < M; i++)S[i].insert(1 << 30);
for(int i = 0; i < n; i++){
cin >> a[i];
v ^= a[i];
for(int j = 0; j < M; j++){
if(a[i] >> j & 1)S[j].insert(i);
}
}
auto update = [&](int p, int x){
v ^= a[p];
for(int j = 0; j < M; j++){
if(a[p] >> j & 1)S[j].erase(p);
}
a[p] -= x;
v ^= a[p];
for(int j = 0; j < M; j++){
if(a[p] >> j & 1)S[j].insert(p);
}
};
auto my_turn = [&](){
int p = *S[__lg(v)].begin();
while(p >> 30 & 1) ;
cout << p + 1 << " " << a[p] - (v ^ a[p]) << endl;
update(p, a[p] - (v ^ a[p]));
};
if(v == 0){
cout << 0 << endl;
cin >> p >> x;
update(--p, x);
}else{
cout << 1 << endl;
my_turn();
}
while(true){
cin >> s;
if(s == -1)return 0;
my_turn();
cin >> s;
if(s == -1)return 0;
cin >> p >> x;
update(--p, x);
}
}