結果

問題 No.153 石の山
ユーザー parenthesesparentheses
提出日時 2021-05-06 13:18:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,278 bytes
コンパイル時間 2,019 ms
コンパイル使用メモリ 202,564 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-12 06:00:24
合計ジャッジ時間 3,168 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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) 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