結果
問題 | No.153 石の山 |
ユーザー |
|
提出日時 | 2020-08-23 10:41:08 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 5,000 ms |
コード長 | 760 bytes |
コンパイル時間 | 966 ms |
コンパイル使用メモリ | 80,108 KB |
最終ジャッジ日時 | 2025-01-13 12:23:58 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 27 |
ソースコード
#include <iostream> #include <vector> #include <set> void solve() { int n; std::cin >> n; std::vector<int> grundy(n + 1, 0); for (int x = 2; x <= n; ++x) { std::set<int> gs; if (x % 2 == 0) { gs.insert(0); } else { gs.insert(grundy[x / 2] ^ grundy[x / 2 + 1]); } if (x >= 3) { if (x % 3 == 1) { gs.insert(grundy[x / 3 + 1]); } else { gs.insert(grundy[x / 3]); } } auto& g = grundy[x]; while (gs.count(g)) ++g; } std::cout << (grundy[n] == 0 ? "B" : "A") << "\n"; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }