結果
問題 |
No.1577 織姫と彦星2
|
ユーザー |
👑 ![]() |
提出日時 | 2021-06-29 17:52:40 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 224 ms / 2,000 ms |
コード長 | 659 bytes |
コンパイル時間 | 361 ms |
コンパイル使用メモリ | 82,004 KB |
実行使用メモリ | 100,288 KB |
最終ジャッジ日時 | 2024-06-25 20:03:10 |
合計ジャッジ時間 | 9,902 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 53 |
ソースコード
def popcount(x): return bin(x).count("1") def Hamming(x,y): return popcount(x^y) #================================================== from collections import deque N=int(input()) S,G=map(int,input().split()) A=list(map(int,input().split())) V=[S,G]+A V_set=set(V) V_ind={v:i for i,v in enumerate(V)} E=[[] for _ in range(N+2)] for i in range(N+2): w=1 for _ in range(40): if V[i]^w in V_set: E[i].append(V_ind[V[i]^w]) w<<=1 X=[-1]*(N+2); X[0]=0 Q=deque([0]) while Q: x=Q.popleft() for y in E[x]: if X[y]==-1: X[y]=X[x]+1 Q.append(y) print(X[1]-1 if X[1]!=-1 else -1)