結果

問題 No.1579 New Type of Nim
コンテスト
ユーザー c-yan
提出日時 2021-07-02 22:20:46
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
WA  
実行時間 -
コード長 967 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,223 ms
コンパイル使用メモリ 20,568 KB
実行使用メモリ 15,360 KB
最終ジャッジ日時 2026-03-18 23:35:53
合計ジャッジ時間 5,443 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3
other AC * 8 WA * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

A, B = map(int, input().split())

def f(a, b, turn):
    if a == 0 or b == 0:
        return turn
    if a >= 5:
        if f(4, b, turn ^ 1) == turn:
            return turn
    if a >= 4:
        if f(3, b, turn ^ 1) == turn:
            return turn
    if a >= 3:
        if f(2, b, turn ^ 1) == turn:
            return turn
    if a >= 2:
        if f(1, b, turn ^ 1) == turn:
            return turn
    if a >= 1:
        if f(0, b, turn ^ 1) == turn:
            return turn
    if b >= 5:
        if f(a, 4, turn ^ 1) == turn:
            return turn
    if b >= 4:
        if f(a, 3, turn ^ 1) == turn:
            return turn
    if b >= 3:
        if f(a, 2, turn ^ 1) == turn:
            return turn
    if b >= 2:
        if f(a, 1, turn ^ 1) == turn:
            return turn
    if b >= 1:
        if f(a, 0, turn ^ 1) == turn:
            return turn
    return turn ^ 1

turn = f(A, B, 0)
if turn == 0:
    print('P')
elif turn == 1:
    print('Q')
0