結果
問題 | No.153 石の山 |
ユーザー |
![]() |
提出日時 | 2017-02-15 10:54:16 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 731 bytes |
コンパイル時間 | 907 ms |
コンパイル使用メモリ | 73,200 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-29 22:53:30 |
合計ジャッジ時間 | 2,099 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 27 |
ソースコード
#include <iostream>#include <set>using namespace std;int memo[101], n;int grundy(int x) {if (memo[x] != 0 || x == 1 || x == 2)return memo[x];set<int>s;if (x % 2 == 0) {s.insert(grundy(x / 2) ^ grundy(x / 2));}else {s.insert(grundy(x / 2) ^ grundy(x / 2 + 1));}if (x % 3 == 0) {s.insert(grundy(x / 3) ^ grundy(x / 3) ^ grundy(x / 3));}else if (x % 3 == 1) {s.insert(grundy(x / 3) ^ grundy(x / 3) ^ grundy(x / 3 + 1));}else {s.insert(grundy(x / 3) ^ grundy(x / 3 + 1) ^ grundy(x / 3 + 1));}int g = 0;while (s.count(g) != 0)g++;return memo[x] = g;}int main() {cin >> n;memo[1] = 0;memo[2] = 1;if (grundy(n)) {cout << "A" << endl;}else {cout << "B" << endl;}}