結果

問題 No.683 Two Operations No.3
ユーザー gew1fw
提出日時 2025-06-12 16:37:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 1,095 bytes
コンパイル時間 342 ms
コンパイル使用メモリ 82,588 KB
実行使用メモリ 62,024 KB
最終ジャッジ日時 2025-06-12 16:37:42
合計ジャッジ時間 1,580 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

def can_reach(A, B):
    from collections import deque

    visited = set()
    queue = deque()
    queue.append((A, B))
    visited.add((A, B))

    while queue:
        x, y = queue.popleft()

        if x == 0 and y == 0:
            return True
        if x == 0:
            return True
        if y == 0:
            return True

        # Check if both are odd
        if x % 2 == 1 and y % 2 == 1:
            continue

        # Try reverse of operation1: X = X //2, Y = Y-1
        if x % 2 == 0 and y >= 1:
            new_x = x // 2
            new_y = y - 1
            if (new_x, new_y) not in visited:
                visited.add((new_x, new_y))
                queue.append((new_x, new_y))

        # Try reverse of operation2: X = X-1, Y = Y //2
        if y % 2 == 0 and x >= 1:
            new_x = x - 1
            new_y = y // 2
            if (new_x, new_y) not in visited:
                visited.add((new_x, new_y))
                queue.append((new_x, new_y))

    return False

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