結果
| 問題 | No.2165 Let's Play Nim! |
| コンテスト | |
| ユーザー |
Kude
|
| 提出日時 | 2022-12-16 09:01:42 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 223 ms / 2,000 ms |
| コード長 | 2,283 bytes |
| 記録 | |
| コンパイル時間 | 2,072 ms |
| コンパイル使用メモリ | 197,180 KB |
| 最終ジャッジ日時 | 2025-02-09 14:16:19 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 38 |
ソースコード
#include<bits/stdc++.h>
namespace {
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
template<int element_size>
struct array_set {
int state[element_size]; // -1 if not in set else index in elems
int elems[element_size];
int size = 0;
array_set() { memset(state, -1, sizeof(int) * element_size); }
void insert(int x) {
if (state[x] == -1) {
state[x] = size;
elems[size] = x;
size++;
}
}
bool contains(int x) { return state[x] != -1; }
int* begin() { return elems; }
int* end() { return elems + size; }
void clear() { while(size) state[elems[--size]] = -1; }
void erase(int x) { // not tested
int idx = state[x];
if (idx != -1) {
state[x] = -1;
size--;
if (idx != size) {
int y = elems[size];
state[y] = idx;
elems[idx] = y;
}
}
}
};
constexpr int M = 75000;
array_set<M> st[17];
} int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
VI a(n);
rep(i, n) {
cin >> a[i];
rep(k, 17) if (a[i] >> k & 1) st[k].insert(i);
}
int g = 0;
rrep(i, n) g ^= a[i];
cout << int(g != 0) << endl;
while(true) {
if (g) {
int msb = 31 - __builtin_clz(g);
int i = st[msb].elems[0];
int x = a[i], nx = x ^ g;
a[i] = nx;
cout << i + 1 << ' ' << x - nx << endl;
rrep(k, msb + 1) if (g >> k & 1) {
if (x >> k & 1) st[k].erase(i);
else st[k].insert(i);
}
g = 0;
} else {
int i, dec;
cin >> i >> dec;
i--;
int x = a[i], nx = x - dec;
a[i] = nx;
g = x ^ nx;
rrep(k, 17) if (g >> k & 1) {
if (x >> k & 1) st[k].erase(i);
else st[k].insert(i);
}
}
int ret;
cin >> ret;
if (ret == -1) exit(0);
}
}
Kude