結果

問題 No.1577 織姫と彦星2
ユーザー gorugo30gorugo30
提出日時 2021-06-29 14:43:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 212 ms / 2,000 ms
コード長 713 bytes
コンパイル時間 425 ms
コンパイル使用メモリ 86,852 KB
実行使用メモリ 94,596 KB
最終ジャッジ日時 2023-09-08 00:16:41
合計ジャッジ時間 11,092 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
71,596 KB
testcase_01 AC 87 ms
71,776 KB
testcase_02 AC 86 ms
71,596 KB
testcase_03 AC 87 ms
71,856 KB
testcase_04 AC 85 ms
71,704 KB
testcase_05 AC 112 ms
79,928 KB
testcase_06 AC 103 ms
78,760 KB
testcase_07 AC 200 ms
89,632 KB
testcase_08 AC 137 ms
82,784 KB
testcase_09 AC 212 ms
94,596 KB
testcase_10 AC 132 ms
82,496 KB
testcase_11 AC 109 ms
78,668 KB
testcase_12 AC 156 ms
86,328 KB
testcase_13 AC 125 ms
81,732 KB
testcase_14 AC 172 ms
88,248 KB
testcase_15 AC 129 ms
81,164 KB
testcase_16 AC 193 ms
89,988 KB
testcase_17 AC 150 ms
84,364 KB
testcase_18 AC 97 ms
77,328 KB
testcase_19 AC 178 ms
88,620 KB
testcase_20 AC 164 ms
86,820 KB
testcase_21 AC 189 ms
90,048 KB
testcase_22 AC 186 ms
89,572 KB
testcase_23 AC 135 ms
81,716 KB
testcase_24 AC 187 ms
94,180 KB
testcase_25 AC 127 ms
81,112 KB
testcase_26 AC 133 ms
82,164 KB
testcase_27 AC 183 ms
91,132 KB
testcase_28 AC 166 ms
87,308 KB
testcase_29 AC 141 ms
85,040 KB
testcase_30 AC 146 ms
85,096 KB
testcase_31 AC 195 ms
89,748 KB
testcase_32 AC 105 ms
78,640 KB
testcase_33 AC 101 ms
77,892 KB
testcase_34 AC 139 ms
84,284 KB
testcase_35 AC 179 ms
88,604 KB
testcase_36 AC 183 ms
89,700 KB
testcase_37 AC 205 ms
94,400 KB
testcase_38 AC 206 ms
94,232 KB
testcase_39 AC 139 ms
83,072 KB
testcase_40 AC 137 ms
83,500 KB
testcase_41 AC 177 ms
92,384 KB
testcase_42 AC 155 ms
86,572 KB
testcase_43 AC 158 ms
86,676 KB
testcase_44 AC 105 ms
78,596 KB
testcase_45 AC 125 ms
80,904 KB
testcase_46 AC 123 ms
81,268 KB
testcase_47 AC 166 ms
92,136 KB
testcase_48 AC 135 ms
83,584 KB
testcase_49 AC 147 ms
84,488 KB
testcase_50 AC 129 ms
81,576 KB
testcase_51 AC 105 ms
78,512 KB
testcase_52 AC 194 ms
94,328 KB
testcase_53 AC 194 ms
94,296 KB
testcase_54 AC 145 ms
85,256 KB
testcase_55 AC 183 ms
94,188 KB
testcase_56 AC 128 ms
81,044 KB
testcase_57 AC 120 ms
79,324 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

p2 = [1]
while p2[-1] * 2 <= 10 ** 9:
    p2.append(p2[-1] * 2)
N = int(input())
st, en = map(int, input().split())
S = [st] + list(map(int, input().split())) + [en]

dic = {S[i]: i for i in range(N + 2)}
adj = [[] for i in range(N + 2)]
for i in range(N + 2):
    for j in range(len(p2)):
        if S[i] ^ p2[j] in dic.keys():
            adj[i].append(dic[S[i] ^ p2[j]])
        if S[i] ^ p2[j] in dic.keys():
            adj[i].append(dic[S[i] ^ p2[j]])

from collections import deque
qu = deque([0])
dist = [-1] * (N + 2)
dist[0] = 0
while len(qu):
    v = qu.popleft()
    for nv in adj[v]:
        if dist[nv] == -1:
            dist[nv] = dist[v] + 1
            qu.append(nv)
print(max(-1, dist[-1] - 1))
0