結果
問題 |
No.153 石の山
|
ユーザー |
|
提出日時 | 2018-10-09 18:35:00 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 780 bytes |
コンパイル時間 | 623 ms |
コンパイル使用メモリ | 73,728 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-12 16:38:05 |
合計ジャッジ時間 | 1,383 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 27 |
ソースコード
#include<iostream> #include<set> using namespace std; int gr[110]; void init_grundy(){ gr[1] = 0; for(int i = 2; i < 110; i++) gr[i] = -1; } int grundy(int x){ if(gr[x] >= 0) return gr[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){ 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 res = 0; while(s.find(res) != s.end()) res++; return gr[x] = res; } int main(){ int n, ans = 0; cin >> n; init_grundy(); if(grundy(n)){ cout << "A" << endl; }else{ cout << "B" << endl; } return 0; }