結果
| 問題 |
No.2165 Let's Play Nim!
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-12-16 02:50:11 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,276 bytes |
| コンパイル時間 | 1,638 ms |
| コンパイル使用メモリ | 178,060 KB |
| 実行使用メモリ | 40,848 KB |
| 平均クエリ数 | 12194.62 |
| 最終ジャッジ日時 | 2024-11-15 06:57:03 |
| 合計ジャッジ時間 | 20,962 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 7 RE * 29 TLE * 2 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int msb(int v){
if(v == 0)return -1;
int res = 0;
while(v >> res)res++;
res--;
return res;
}
int main(){
//ios::sync_with_stdio(false);
//cin.tie(0);
int n, v = 0, p, x, s;
cin >> n;
vector<int> a(n);
set<pair<int,int>> S;
for(int i = 0; i < n; i++){
cin >> a[i];
v ^= a[i];
S.insert({a[i], i});
}
auto update = [&](int p, int x){
S.erase(make_pair(a[p], p));
v ^= a[p];
a[p] -= x;
v ^= a[p];
S.insert(make_pair(a[p], p));
};
auto my_turn = [&](){
int v2 = 1 << msb(v);
auto it = S.rbegin();
int p = it -> second;
if((v ^ a[p]) > a[p]){
auto it = S.lower_bound(make_pair(v2, -1));
p = it -> second;
}
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)break;
my_turn();
cin >> s;
if(s == -1)break;
cin >> p >> x;
update(--p, x);
}
}