結果
問題 |
No.153 石の山
|
ユーザー |
|
提出日時 | 2016-09-29 22:14:52 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 1,080 bytes |
コンパイル時間 | 691 ms |
コンパイル使用メモリ | 78,932 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-21 10:41:51 |
合計ジャッジ時間 | 1,559 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 27 |
ソースコード
#include <iostream> #include <vector> #include <set> #define repeat(i,n) for (int i = 0; (i) < (n); ++(i)) using namespace std; template <typename C> int mex(C const & xs) { int y = 0; for (int x : xs) { // xs must be sorted (duplication is permitted) if (y < x) break; if (y == x) ++ y; } return y; } int main() { int n; cin >> n; vector<int> grandy(n+1); repeat (x,n+1) { set<int> s; if (x >= 2) { if (x % 2 == 0) { s.insert(grandy[x/2] ^ grandy[x/2]); } else { s.insert(grandy[x/2] ^ grandy[x/2+1]); } } if (x >= 3) { if (x % 3 == 0) { s.insert(grandy[x/3] ^ grandy[x/3] ^ grandy[x/3]); } else if (x % 3 == 1) { s.insert(grandy[x/3] ^ grandy[x/3] ^ grandy[x/3+1]); } else { s.insert(grandy[x/3] ^ grandy[x/3+1] ^ grandy[x/3+1]); } } grandy[x] = mex(s); } cout << (grandy[n] ? "A" : "B") << endl; return 0; }