結果

問題 No.1577 織姫と彦星2
ユーザー 👑 KazunKazun
提出日時 2021-06-29 17:52:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 247 ms / 2,000 ms
コード長 659 bytes
コンパイル時間 321 ms
コンパイル使用メモリ 87,172 KB
実行使用メモリ 104,748 KB
最終ジャッジ日時 2023-09-08 02:53:52
合計ジャッジ時間 12,081 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
71,400 KB
testcase_01 AC 95 ms
71,588 KB
testcase_02 AC 91 ms
71,388 KB
testcase_03 AC 90 ms
71,708 KB
testcase_04 AC 91 ms
71,712 KB
testcase_05 AC 119 ms
79,652 KB
testcase_06 AC 107 ms
77,948 KB
testcase_07 AC 228 ms
96,916 KB
testcase_08 AC 144 ms
81,348 KB
testcase_09 AC 247 ms
104,748 KB
testcase_10 AC 141 ms
81,620 KB
testcase_11 AC 111 ms
78,200 KB
testcase_12 AC 168 ms
86,328 KB
testcase_13 AC 125 ms
80,376 KB
testcase_14 AC 180 ms
90,164 KB
testcase_15 AC 130 ms
79,544 KB
testcase_16 AC 207 ms
92,364 KB
testcase_17 AC 153 ms
83,644 KB
testcase_18 AC 99 ms
77,820 KB
testcase_19 AC 195 ms
90,232 KB
testcase_20 AC 177 ms
86,964 KB
testcase_21 AC 206 ms
92,384 KB
testcase_22 AC 207 ms
92,252 KB
testcase_23 AC 137 ms
80,444 KB
testcase_24 AC 228 ms
103,276 KB
testcase_25 AC 134 ms
78,980 KB
testcase_26 AC 141 ms
80,396 KB
testcase_27 AC 203 ms
94,672 KB
testcase_28 AC 176 ms
88,304 KB
testcase_29 AC 152 ms
84,736 KB
testcase_30 AC 158 ms
84,836 KB
testcase_31 AC 213 ms
92,496 KB
testcase_32 AC 103 ms
77,964 KB
testcase_33 AC 99 ms
77,660 KB
testcase_34 AC 144 ms
83,548 KB
testcase_35 AC 191 ms
90,388 KB
testcase_36 AC 197 ms
92,240 KB
testcase_37 AC 238 ms
104,240 KB
testcase_38 AC 235 ms
104,156 KB
testcase_39 AC 144 ms
81,492 KB
testcase_40 AC 142 ms
82,496 KB
testcase_41 AC 202 ms
96,900 KB
testcase_42 AC 166 ms
88,472 KB
testcase_43 AC 165 ms
88,452 KB
testcase_44 AC 102 ms
78,116 KB
testcase_45 AC 121 ms
78,476 KB
testcase_46 AC 121 ms
79,560 KB
testcase_47 AC 187 ms
96,936 KB
testcase_48 AC 141 ms
82,524 KB
testcase_49 AC 154 ms
83,696 KB
testcase_50 AC 134 ms
80,656 KB
testcase_51 AC 108 ms
78,220 KB
testcase_52 AC 221 ms
99,656 KB
testcase_53 AC 231 ms
103,416 KB
testcase_54 AC 154 ms
84,860 KB
testcase_55 AC 209 ms
99,404 KB
testcase_56 AC 132 ms
79,560 KB
testcase_57 AC 121 ms
78,312 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0