結果
| 問題 |
No.683 Two Operations No.3
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 21:38:04 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 49 ms / 2,000 ms |
| コード長 | 1,095 bytes |
| コンパイル時間 | 163 ms |
| コンパイル使用メモリ | 82,256 KB |
| 実行使用メモリ | 61,840 KB |
| 最終ジャッジ日時 | 2025-06-12 21:41:28 |
| 合計ジャッジ時間 | 1,664 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 |
ソースコード
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")
gew1fw