結果

問題 No.153 石の山
ユーザー なおなお
提出日時 2015-02-16 01:08:46
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,035 bytes
コンパイル時間 1,384 ms
コンパイル使用メモリ 164,072 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-22 15:24:10
合計ジャッジ時間 2,290 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define REP(i, n)           for(int(i)=0;(i)<(n);++(i))
#define FOR(i, f, t)        for(int(i)=(f);(i)<(t);(++i))
#define RREP(i, n)          for(int(i)=(n)-1;(i)>=0;--(i))
const int MOD = int(1e9+7);

const int MAXN = 100;
int dp[MAXN+1];
int grundy(const int n){
    if(n == 1) return 0;
    if(dp[n] >= 0) return dp[n];

    // 状態遷移先
    set<int> s;
    int m1,m2,m3;
    m1 = n/2, m2 = n-m1;
    s.insert(grundy(m1)^grundy(m2));

    if(n >= 3){
        m1 = n/3, m2 = (n-m1)/2, m3 = n-m1-m2;
        s.insert(grundy(m1)^grundy(m2)^grundy(m3));
    }

    int g = 0;
    while(s.count(g)) g++;
    cerr<<"grundy["<<n<<"]="<<g<<" =>";
    for(auto it=s.begin(); it!=s.end(); ++it) cerr<<" "<<*it;
    cerr<<endl;
    return dp[n] = g;
}

int main(){
    memset(dp,-1,sizeof(dp));
    REP(i,MAXN) grundy(i+1);

    int N; cin >> N;
    cout << (grundy(N)?"A":"B") << endl;
}
0