結果
| 問題 | No.683 Two Operations No.3 |
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 21:37:38 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 1,862 bytes |
| コンパイル時間 | 192 ms |
| コンパイル使用メモリ | 82,456 KB |
| 実行使用メモリ | 583,744 KB |
| 最終ジャッジ日時 | 2025-06-12 21:40:19 |
| 合計ジャッジ時間 | 4,196 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 6 MLE * 1 -- * 9 |
ソースコード
from collections import deque
def can_reach(A, B):
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
# Try reverse operation 1
if x % 2 == 0 and y >= 1:
new_x = x // 2
new_y = y - 1
if new_x >= 0 and new_y >= 0 and (new_x, new_y) not in visited:
visited.add((new_x, new_y))
queue.append((new_x, new_y))
if new_x == 0 and new_y == 0:
return True
# Try reverse operation 2
if y % 2 == 0 and x >= 1:
new_x = x - 1
new_y = y // 2
if new_x >= 0 and new_y >= 0 and (new_x, new_y) not in visited:
visited.add((new_x, new_y))
queue.append((new_x, new_y))
if new_x == 0 and new_y == 0:
return True
# If both are even, try both possibilities
if x % 2 == 0 and y % 2 == 0:
new_x1 = x // 2
new_y1 = y - 1
if new_x1 >= 0 and new_y1 >= 0 and (new_x1, new_y1) not in visited:
visited.add((new_x1, new_y1))
queue.append((new_x1, new_y1))
if new_x1 == 0 and new_y1 == 0:
return True
new_x2 = x - 1
new_y2 = y // 2
if new_x2 >= 0 and new_y2 >= 0 and (new_x2, new_y2) not in visited:
visited.add((new_x2, new_y2))
queue.append((new_x2, new_y2))
if new_x2 == 0 and new_y2 == 0:
return True
return False
# Read input
A, B = map(int, input().split())
if can_reach(A, B):
print("Yes")
else:
print("No")
gew1fw