結果

問題 No.1576 織姫と彦星
ユーザー pluto77
提出日時 2022-02-18 10:22:24
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 36 ms / 2,000 ms
コード長 390 bytes
コンパイル時間 77 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-06-29 08:00:09
合計ジャッジ時間 3,245 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 54
権限があれば一括ダウンロードができます

ソースコード

diff #

#yuki1576
from collections import deque
n=int(input())
s,e=map(int,input().split())
st=list(map(int,input().split()))
dist={x:-1 for x in st}
dist[s]=0
dist[e]=-1
d=deque()
d.append(s)
while d:
 v=d.popleft()
 for x in range(30):
  i=v^(2**x)
  if i not in dist:
   continue
  if dist[i]!=-1:
   continue
  dist[i]=dist[v]+1
  d.append(i)
if dist[e]==-1:
 print(-1)
else:
 print(dist[e]-1)
0