結果
| 問題 | No.2165 Let's Play Nim! |
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2026-08-11 13:53:20 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
AC
|
| 実行時間 | 150 ms / 2,000 ms |
| + 1µs | |
| コード長 | 1,723 bytes |
| 記録 | |
| コンパイル時間 | 2,419 ms |
| コンパイル使用メモリ | 333,508 KB |
| 実行使用メモリ | 6,016 KB |
| 平均クエリ数 | 863.56 |
| 最終ジャッジ日時 | 2026-08-11 13:53:31 |
| 合計ジャッジ時間 | 10,102 ms |
|
ジャッジサーバーID (参考情報) |
judge2_1 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 38 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define debug(x) cout << "(" << #x << " : " << (x) << ")" << endl
#define debughere cout << "HERE" << endl
void solve() {
int n; cin >> n;
int xor_product = 0;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
xor_product ^= a[i];
}
bool turn = (xor_product == 0 ? 0 : 1);
cout << turn << endl;
while (true) {
if (turn == 1) { // giliran kita
// untuk mencari suatu nilai yang bisa kita
// buang supaya xornya 0,
// kita bisa cari angka yang mengandung MSB dari
// xor_product sekarang (MSB: most signficant bit)
int msb = 1 << __lg(xor_product);
// __lg() -> floor(log2())
for (int i = 0; i < n; i++) {
if (a[i] & msb) {
cout << i + 1 << ' '
<< a[i] - (a[i] ^ xor_product) << endl;
a[i] ^= xor_product;
xor_product = 0;
break;
}
}
// xor becomes 0
} else { // giliran judge
int i, k; cin >> i >> k; i--;
xor_product = a[i] ^ (a[i] - k);
a[i] -= k;
// xor becomes non-0
}
int ret; cin >> ret; // ini cuma pernah input iterasi pertama
if (ret == -1) return;
turn ^= 1;
}
// tujuan kita menang, maka kalo xor == 0, pilih player 2
// selain itu, pilih player 1
}
signed main() {
ios_base::sync_with_stdio(false), cin.tie(nullptr);
int t = 1;
// cin >> t;
while (t--)
solve();
return 0;
}
vjudge1