結果

問題 No.683 Two Operations No.3
ユーザー NoneNone
提出日時 2021-03-05 20:19:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 40 ms / 2,000 ms
コード長 591 bytes
コンパイル時間 337 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 52,352 KB
最終ジャッジ日時 2024-10-06 22:48:02
合計ジャッジ時間 1,810 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

def dfs(start=0,goal=None):
    parents={}
    p,t=start,0
    parents[p]=-2
    next_set=[(p,t)]
    if p==goal:
        return t
    while next_set:
        p,t=next_set.pop()
        for q in make_edges(p):
            if q in parents:
                continue
            if q[0]==0 or q[1]==0:
                return 1
            parents[q]=p
            next_set.append((q,t+1))
    return 0

def make_edges(p):
    a,b=p
    if a%2==0:
        yield a//2, b-1
    if b%2==0:
        yield a-1, b//2


A,B=map(int, input().split())
res=dfs(start=(A,B))
print("Yes" if res else "No")

0