結果

問題 No.683 Two Operations No.3
ユーザー gew1fw
提出日時 2025-06-12 16:37:56
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,168 bytes
コンパイル時間 309 ms
コンパイル使用メモリ 82,900 KB
実行使用メモリ 66,904 KB
最終ジャッジ日時 2025-06-12 16:38:03
合計ジャッジ時間 3,925 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 4 WA * 2 TLE * 1 -- * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

def can_reach_zero(A, B):
    while True:
        if A == 0 and B == 0:
            return True
        # Check if both are odd and greater than zero
        if (A % 2 == 1) and (B % 2 == 1) and (A != 0 or B != 0):
            return False
        # Check possible operations
        op1_possible = False
        new_a1 = 0
        new_b1 = 0
        if A % 2 == 0 and B >= 1:
            op1_possible = True
            new_a1 = A // 2
            new_b1 = B - 1
        op2_possible = False
        new_a2 = 0
        new_b2 = 0
        if B % 2 == 0 and A >= 1:
            op2_possible = True
            new_a2 = A - 1
            new_b2 = B // 2
        if not op1_possible and not op2_possible:
            return False
        if op1_possible and op2_possible:
            sum1 = new_a1 + new_b1
            sum2 = new_a2 + new_b2
            if sum1 <= sum2:
                A, B = new_a1, new_b1
            else:
                A, B = new_a2, new_b2
        elif op1_possible:
            A, B = new_a1, new_b1
        else:
            A, B = new_a2, new_b2

A, B = map(int, input().split())
if can_reach_zero(A, B):
    print("Yes")
else:
    print("No")
0