結果

問題 No.3112 Decrement or Mod Game
ユーザー aaaaaaaaaaa
提出日時 2025-04-19 13:11:37
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
MLE  
実行時間 -
コード長 1,098 bytes
コンパイル時間 1,066 ms
コンパイル使用メモリ 84,460 KB
実行使用メモリ 529,956 KB
最終ジャッジ日時 2025-04-19 13:12:04
合計ジャッジ時間 4,618 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 3
other AC * 2 MLE * 1 -- * 62
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <numeric>
#include <map>
#include <algorithm>
#include <utility>

using namespace std;

typedef unsigned long long ull;

map<pair<ull, ull>, bool> memo;

bool solve(ull a, ull b) {
    if (b == 0) {
        return true;
    }
    if (a == 0) {
        return false;
    }

    pair<ull, ull> state = {a, b};
    if (memo.count(state)) {
        return memo[state];
    }

    bool result;

    if (a < b) {
        result = !solve(b, a - 1);
    } else { // a >= b
        if (b > 0 && a >= 2 * b) {
            result = true;
        } else {
            bool win_via_mod = false;
            if (b > 0) {
                 win_via_mod = !solve(b, a % b);
            }

            bool win_via_sub = !solve(b, a - 1);

            result = win_via_mod || win_via_sub;
        }
    }

    return memo[state] = result;
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ull a, b;
    cin >> a >> b;

    if (solve(a, b)) {
        cout << "Alice" << endl;
    } else {
        cout << "Bob" << endl;
    }

    return 0;
}
0