結果

問題 No.1577 織姫と彦星2
ユーザー AEnAEn
提出日時 2022-11-22 00:18:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 181 ms / 2,000 ms
コード長 598 bytes
コンパイル時間 1,163 ms
コンパイル使用メモリ 81,636 KB
実行使用メモリ 94,064 KB
最終ジャッジ日時 2023-10-23 19:40:29
合計ジャッジ時間 9,741 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
55,532 KB
testcase_01 AC 41 ms
55,532 KB
testcase_02 AC 41 ms
55,532 KB
testcase_03 AC 43 ms
55,532 KB
testcase_04 AC 41 ms
55,532 KB
testcase_05 AC 67 ms
80,368 KB
testcase_06 AC 53 ms
68,672 KB
testcase_07 AC 154 ms
90,432 KB
testcase_08 AC 89 ms
81,876 KB
testcase_09 AC 173 ms
94,064 KB
testcase_10 AC 80 ms
82,140 KB
testcase_11 AC 58 ms
68,804 KB
testcase_12 AC 108 ms
85,620 KB
testcase_13 AC 75 ms
81,024 KB
testcase_14 AC 125 ms
89,436 KB
testcase_15 AC 82 ms
80,436 KB
testcase_16 AC 150 ms
90,120 KB
testcase_17 AC 100 ms
83,740 KB
testcase_18 AC 48 ms
62,032 KB
testcase_19 AC 141 ms
89,624 KB
testcase_20 AC 118 ms
85,976 KB
testcase_21 AC 148 ms
90,064 KB
testcase_22 AC 140 ms
90,088 KB
testcase_23 AC 88 ms
81,052 KB
testcase_24 AC 142 ms
93,688 KB
testcase_25 AC 80 ms
80,232 KB
testcase_26 AC 91 ms
81,292 KB
testcase_27 AC 109 ms
91,076 KB
testcase_28 AC 118 ms
88,700 KB
testcase_29 AC 87 ms
84,492 KB
testcase_30 AC 97 ms
84,584 KB
testcase_31 AC 138 ms
90,456 KB
testcase_32 AC 57 ms
68,824 KB
testcase_33 AC 52 ms
64,448 KB
testcase_34 AC 90 ms
83,624 KB
testcase_35 AC 137 ms
89,976 KB
testcase_36 AC 136 ms
90,056 KB
testcase_37 AC 181 ms
93,676 KB
testcase_38 AC 175 ms
93,760 KB
testcase_39 AC 92 ms
81,876 KB
testcase_40 AC 88 ms
82,804 KB
testcase_41 AC 128 ms
92,160 KB
testcase_42 AC 92 ms
86,600 KB
testcase_43 AC 104 ms
88,760 KB
testcase_44 AC 57 ms
68,808 KB
testcase_45 AC 77 ms
79,476 KB
testcase_46 AC 73 ms
80,416 KB
testcase_47 AC 106 ms
92,212 KB
testcase_48 AC 80 ms
82,864 KB
testcase_49 AC 99 ms
83,708 KB
testcase_50 AC 82 ms
81,016 KB
testcase_51 AC 56 ms
70,840 KB
testcase_52 AC 138 ms
94,064 KB
testcase_53 AC 145 ms
93,752 KB
testcase_54 AC 90 ms
84,584 KB
testcase_55 AC 134 ms
93,748 KB
testcase_56 AC 92 ms
80,432 KB
testcase_57 AC 64 ms
73,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict, deque
N = int(input())
start, end = map(int,input().split())
s = [start]+list(map(int, input().split()))+[end]

d = {s[i]:i for i in range(N+2)}
G = [list() for _ in range(N+2)]
q = deque
for i in range(N+2):
    for j in range(30):
        G[i].append(s[i]^(1<<j))

q = deque()
dis = [-1]*(N+2)
q.append(0)
dis[0] = 0
while q:
    v = q.popleft()
    for nex in G[v]:
        if nex in d:
            nex_id = d[nex]
            if dis[nex_id]==-1:
                dis[nex_id] = dis[v]+1
                q.append(nex_id)
print(-1 if dis[-1]==-1 else dis[-1]-1)
0