結果
| 問題 |
No.153 石の山
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-12-31 18:17:07 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 16 ms / 5,000 ms |
| コード長 | 658 bytes |
| コンパイル時間 | 1,945 ms |
| コンパイル使用メモリ | 194,548 KB |
| 最終ジャッジ日時 | 2025-02-09 22:25:59 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 27 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int dfs(vector<int> &g, int N) {
if (g[N] != -1) return g[N];
int a = 0;
if (N % 2 == 1) {
a ^= dfs(g, N/2);
a ^= dfs(g, N/2+1);
}
int b = 0;
if (N % 3 != 1) {
b ^= dfs(g, N/3);
} else {
b ^= dfs(g, N/3+1);
}
for (int i = 0; i < 3; i++) {
if (a == i || b == i) continue;
g[N] = i;
break;
}
return g[N];
}
int main() {
int N;
cin >> N;
vector<int> grundy(N+1, -1);
grundy[1] = 0; grundy[2] = 1;
dfs(grundy, N);
if (grundy[N] == 0) cout << "B" << endl;
else cout << "A" << endl;
}