結果

問題 No.1577 織姫と彦星2
ユーザー 👑 Kazun
提出日時 2021-06-29 17:54:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 178 ms / 2,000 ms
コード長 617 bytes
コンパイル時間 162 ms
コンパイル使用メモリ 82,212 KB
実行使用メモリ 100,224 KB
最終ジャッジ日時 2024-06-25 20:05:04
合計ジャッジ時間 8,114 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 53
権限があれば一括ダウンロードができます

ソースコード

diff #

def Hamming(x,y):
    return bin(x^y).count("1")
#==================================================
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(30):
        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)
0