結果

問題 No.153 石の山
ユーザー codershifthcodershifth
提出日時 2015-10-06 09:31:40
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,522 bytes
コンパイル時間 1,614 ms
コンパイル使用メモリ 172,660 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-22 15:33:58
合計ジャッジ時間 2,512 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
testcase_25 AC 1 ms
5,376 KB
testcase_26 AC 1 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 1 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int (i)=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define RANGE(vec) (vec).begin(),(vec).end()

using namespace std;


class PilesOfStones {
public:
    // grundy 数で解く
    void solve(void) {
            int N;
            cin>>N;
            map<int,int> memo;
            function<int(int)> grundy = [&](int n) {
                if (memo.count(n))
                    return memo[n];
                if (n <= 1)
                    return 0;
                set<int> S;
                if (n%2 == 0)
                    S.insert(grundy(n/2) ^ grundy(n/2));
                if (n%2 == 1)
                    S.insert(grundy(n/2) ^ grundy(n/2+1));
                if (n%3 == 0)
                    S.insert(grundy(n/3) ^ grundy(n/3) ^ grundy(n/3));
                if (n%3 == 1)
                    S.insert(grundy(n/3) ^ grundy(n/3) ^ grundy(n/3+1));
                if (n%3 == 2)
                    S.insert(grundy(n/3) ^ grundy(n/3+1) ^ grundy(n/3+1));
                int res = 0;
                while (S.count(res))
                    ++res;
                return memo[n] = res;
            };
            if (grundy(N))
                cout<<"A"<<endl;
            else
                cout<<"B"<<endl;
    }
};

#if 1
int main(int argc, char *argv[])
{
        ios::sync_with_stdio(false);
        auto obj = new PilesOfStones();
        obj->solve();
        delete obj;
        return 0;
}
#endif
0