結果

問題 No.1577 織姫と彦星2
ユーザー 👑 KazunKazun
提出日時 2021-06-29 17:54:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 215 ms / 2,000 ms
コード長 617 bytes
コンパイル時間 275 ms
コンパイル使用メモリ 87,292 KB
実行使用メモリ 104,792 KB
最終ジャッジ日時 2023-09-08 02:55:54
合計ジャッジ時間 11,115 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
71,888 KB
testcase_01 AC 84 ms
71,788 KB
testcase_02 AC 88 ms
71,796 KB
testcase_03 AC 89 ms
71,740 KB
testcase_04 AC 86 ms
71,840 KB
testcase_05 AC 106 ms
79,692 KB
testcase_06 AC 96 ms
77,964 KB
testcase_07 AC 193 ms
96,808 KB
testcase_08 AC 129 ms
81,408 KB
testcase_09 AC 215 ms
104,792 KB
testcase_10 AC 126 ms
81,632 KB
testcase_11 AC 107 ms
78,304 KB
testcase_12 AC 151 ms
86,396 KB
testcase_13 AC 122 ms
80,480 KB
testcase_14 AC 168 ms
90,068 KB
testcase_15 AC 125 ms
79,452 KB
testcase_16 AC 185 ms
92,520 KB
testcase_17 AC 142 ms
83,784 KB
testcase_18 AC 97 ms
77,384 KB
testcase_19 AC 172 ms
90,400 KB
testcase_20 AC 157 ms
86,964 KB
testcase_21 AC 181 ms
92,256 KB
testcase_22 AC 182 ms
92,268 KB
testcase_23 AC 130 ms
80,544 KB
testcase_24 AC 202 ms
103,060 KB
testcase_25 AC 122 ms
78,936 KB
testcase_26 AC 131 ms
80,504 KB
testcase_27 AC 174 ms
94,660 KB
testcase_28 AC 160 ms
88,532 KB
testcase_29 AC 139 ms
84,820 KB
testcase_30 AC 147 ms
85,004 KB
testcase_31 AC 184 ms
92,392 KB
testcase_32 AC 108 ms
77,920 KB
testcase_33 AC 101 ms
77,628 KB
testcase_34 AC 133 ms
83,784 KB
testcase_35 AC 174 ms
90,240 KB
testcase_36 AC 177 ms
92,344 KB
testcase_37 AC 212 ms
104,420 KB
testcase_38 AC 215 ms
104,276 KB
testcase_39 AC 133 ms
81,516 KB
testcase_40 AC 132 ms
82,380 KB
testcase_41 AC 177 ms
96,912 KB
testcase_42 AC 149 ms
88,660 KB
testcase_43 AC 150 ms
88,812 KB
testcase_44 AC 102 ms
78,248 KB
testcase_45 AC 118 ms
78,324 KB
testcase_46 AC 117 ms
79,304 KB
testcase_47 AC 156 ms
96,836 KB
testcase_48 AC 124 ms
82,424 KB
testcase_49 AC 138 ms
83,836 KB
testcase_50 AC 127 ms
80,424 KB
testcase_51 AC 101 ms
78,156 KB
testcase_52 AC 196 ms
103,252 KB
testcase_53 AC 196 ms
103,352 KB
testcase_54 AC 137 ms
84,852 KB
testcase_55 AC 181 ms
99,432 KB
testcase_56 AC 121 ms
79,492 KB
testcase_57 AC 113 ms
78,144 KB
権限があれば一括ダウンロードができます

ソースコード

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