結果
問題 |
No.153 石の山
|
ユーザー |
|
提出日時 | 2019-09-25 15:33:03 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 663 bytes |
コンパイル時間 | 654 ms |
コンパイル使用メモリ | 74,440 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-22 06:47:19 |
合計ジャッジ時間 | 1,520 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 27 |
ソースコード
#include<iostream> #include<set> using namespace std; int grundy[101] = {}; bool vis[101] = {}; int f(int x){ if(x == 1){ vis[x] = true; }else if(x == 2){ vis[x] = true; grundy[x] = 1; } if(vis[x]) return grundy[x]; vis[x] = true; set<int> s; s.insert(f(x/2)^f(x-x/2)); if(x%3 == 0) s.insert(f(x/3)^f(x/3)^f(x/3)); if(x%3 == 1) s.insert(f(x/3)^f(x/3)^f(x/3+1)); if(x%3 == 2) s.insert(f(x/3)^f(x/3+1)^f(x/3+1)); int num = 0; while(s.count(num)) num++; return grundy[x] = num; } int main(){ int n; cin >> n; cout << (f(n) == 0 ? 'B' : 'A') << endl; return 0; }