結果

問題 No.1579 New Type of Nim
ユーザー c-yan
提出日時 2021-07-02 22:20:46
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 967 bytes
コンパイル時間 93 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-06-29 12:00:34
合計ジャッジ時間 2,067 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3
other AC * 8 WA * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

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