結果

問題 No.153 石の山
ユーザー parenthesesparentheses
提出日時 2021-05-06 13:18:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,280 bytes
コンパイル時間 2,128 ms
コンパイル使用メモリ 203,880 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-12 06:01:18
合計ジャッジ時間 5,186 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// --------------------------------------------------------
#define FOR(i,l,r) for (ll i = (l); i < (r); ++i)
#define REP(i,n) FOR(i,0,n)
using VLL = vector<ll>;
using VB = vector<bool>;
// --------------------------------------------------------


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);

    ll N; cin >> N;

    // nimber の最大値 (多めに確保すると無難)
    const ll M = N + 1;

    // nimber (grundy number)
    // 今の状態から一手で行ける状態の nimber に含まれていない最小の非負整数
    VLL nim(N+1); nim[1] = 0;
    FOR(i,2,N+1) {
        VB mex(M,false);
        if (i % 2 == 0) { mex[nim[i/2] ^ nim[i/2]] = true; }
        if (i % 2 == 1) { mex[nim[i/2] ^ nim[i/2 + 1]] = true; }
        if (i % 3 == 0) { mex[nim[i/3] ^ nim[i/3] ^ nim[i/3]] = true; }
        if (i % 3 == 1) { mex[nim[i/3] ^ nim[i/3] ^ nim[i/3 + 1]] = true; }
        if (i % 3 == 2) { mex[nim[i/3] ^ nim[i/3 + 1] ^ nim[i/3 + 1]] = true; }
        REP(i,M+1) if (!mex[i]) nim[i] = i;
    }

    string ans = (nim[N] != 0 ? "A" : "B");
    cout << ans << endl;

    return 0;
}
// Verify: https://yukicoder.me/problems/no/153
0