結果

問題 No.153 石の山
ユーザー izuru_matsuuraizuru_matsuura
提出日時 2016-09-29 21:43:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,261 bytes
コンパイル時間 1,595 ms
コンパイル使用メモリ 166,540 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-01 07:50:26
合計ジャッジ時間 2,604 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 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 WA -
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 WA -
testcase_20 WA -
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 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 WA -
testcase_28 AC 2 ms
5,376 KB
testcase_29 WA -
testcase_30 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

namespace {

    typedef double real;
    typedef long long ll;

    template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) {
        if (vs.empty()) return os << "[]";
        auto i = vs.begin();
        os << "[" << *i;
        for (++i; i != vs.end(); ++i) os << " " << *i;
        return os << "]";
    }
    template<class T> istream& operator>>(istream& is, vector<T>& vs) {
        for (auto it = vs.begin(); it != vs.end(); it++) is >> *it;
        return is;
    }

    int N;
    void input() {
        cin >> N;
    }

    int cache[101];
    bool win(int n) {
        if (cache[n] >= 0) return bool(cache[n]);

        int x, y, z;
        // div 2

        x = n / 2;
        y = n - x;
        if (win(x) ^ win(y) == 0) return cache[n] = true;

        // div 3
        x = n / 3;
        y = (n - x) / 2;
        z = n - x - y;
        if (win(x) ^ win(y) ^ win(z) == 0) return cache[n] = true;

        return cache[n] = false;
    }

    void solve() {
        memset(cache, -1, sizeof(cache));
        cache[1] = false;
        cache[2] = true;
        cache[3] = true;
        cout << (win(N) ? "A" : "B") << endl;
    }
}

int main() {
    input(); solve();
    return 0;
}

0