結果
問題 |
No.1577 織姫と彦星2
|
ユーザー |
![]() |
提出日時 | 2024-02-18 02:53:26 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 132 ms / 2,000 ms |
コード長 | 482 bytes |
コンパイル時間 | 427 ms |
コンパイル使用メモリ | 82,400 KB |
実行使用メモリ | 94,320 KB |
最終ジャッジ日時 | 2024-09-29 00:02:40 |
合計ジャッジ時間 | 6,771 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 53 |
ソースコード
import sys input = sys.stdin.readline from collections import deque N=int(input()) start,end=map(int,input().split()) S=list(map(int,input().split())) S.append(end) S.append(start) SET=set(S) DP=dict() DP[start]=0 Q=deque([start]) while Q: x=Q.popleft() for i in range(32): y=x^(1<<i) if y in SET: if not(y in DP): DP[y]=DP[x]+1 Q.append(y) if end in DP: print(DP[end]-1) else: print(-1)