結果

問題 No.153 石の山
ユーザー cormoran
提出日時 2016-09-29 22:29:34
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 755 bytes
コンパイル時間 1,285 ms
コンパイル使用メモリ 168,576 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-21 10:42:05
合計ジャッジ時間 2,144 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

class Solver {
  public:
    vector<int> g;
    int grundy(int x) {
        if(g[x] >= 0) return g[x];
        set<int> reachable;
        if(x >= 2) reachable.insert(grundy(x / 2) ^ grundy(x / 2 + x % 2));
        if(x >= 3) reachable.insert(grundy(x / 3) ^ grundy(x / 3 + (x % 3) / 2) ^ grundy(x / 3 + (x % 3 ? 1 : 0)));
        int ret = 0;
        for(int a : reachable) if(ret == a) ret++;
        return g[x] = ret;
    }
    
    bool solve() {
        int N; cin >> N;
        g.resize(N + 1, -1);
        g[1] = 0;
        cout << (grundy(N) ? "A" : "B") << endl;
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}
0