結果

問題 No.1577 織姫と彦星2
ユーザー rlangevinrlangevin
提出日時 2023-02-04 12:57:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 202 ms / 2,000 ms
コード長 822 bytes
コンパイル時間 696 ms
コンパイル使用メモリ 86,976 KB
実行使用メモリ 99,044 KB
最終ジャッジ日時 2023-09-16 09:41:13
合計ジャッジ時間 10,871 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
71,620 KB
testcase_01 AC 91 ms
71,524 KB
testcase_02 AC 89 ms
71,544 KB
testcase_03 AC 88 ms
71,512 KB
testcase_04 AC 89 ms
71,712 KB
testcase_05 AC 120 ms
78,780 KB
testcase_06 AC 101 ms
77,872 KB
testcase_07 AC 202 ms
92,992 KB
testcase_08 AC 129 ms
80,016 KB
testcase_09 AC 193 ms
99,044 KB
testcase_10 AC 125 ms
80,512 KB
testcase_11 AC 110 ms
78,008 KB
testcase_12 AC 145 ms
84,260 KB
testcase_13 AC 117 ms
79,232 KB
testcase_14 AC 157 ms
86,932 KB
testcase_15 AC 122 ms
78,812 KB
testcase_16 AC 173 ms
88,608 KB
testcase_17 AC 137 ms
81,924 KB
testcase_18 AC 100 ms
77,324 KB
testcase_19 AC 165 ms
87,120 KB
testcase_20 AC 154 ms
84,432 KB
testcase_21 AC 175 ms
88,360 KB
testcase_22 AC 173 ms
88,508 KB
testcase_23 AC 125 ms
79,216 KB
testcase_24 AC 169 ms
93,296 KB
testcase_25 AC 123 ms
78,436 KB
testcase_26 AC 128 ms
79,424 KB
testcase_27 AC 170 ms
90,256 KB
testcase_28 AC 154 ms
85,744 KB
testcase_29 AC 134 ms
82,852 KB
testcase_30 AC 138 ms
82,980 KB
testcase_31 AC 173 ms
88,536 KB
testcase_32 AC 108 ms
77,832 KB
testcase_33 AC 100 ms
77,500 KB
testcase_34 AC 132 ms
82,076 KB
testcase_35 AC 166 ms
87,204 KB
testcase_36 AC 170 ms
88,752 KB
testcase_37 AC 190 ms
98,480 KB
testcase_38 AC 188 ms
98,196 KB
testcase_39 AC 127 ms
79,972 KB
testcase_40 AC 129 ms
80,816 KB
testcase_41 AC 163 ms
91,596 KB
testcase_42 AC 144 ms
85,780 KB
testcase_43 AC 146 ms
85,684 KB
testcase_44 AC 103 ms
77,992 KB
testcase_45 AC 119 ms
78,136 KB
testcase_46 AC 115 ms
78,644 KB
testcase_47 AC 153 ms
91,624 KB
testcase_48 AC 126 ms
81,408 KB
testcase_49 AC 138 ms
81,824 KB
testcase_50 AC 124 ms
79,092 KB
testcase_51 AC 104 ms
78,140 KB
testcase_52 AC 172 ms
93,608 KB
testcase_53 AC 175 ms
93,272 KB
testcase_54 AC 134 ms
82,956 KB
testcase_55 AC 183 ms
93,384 KB
testcase_56 AC 122 ms
78,704 KB
testcase_57 AC 115 ms
78,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque


def bfs(G, s, N):
    Q = deque([])
    dist = [-1] * N
    par = [-1] * N
    dist[s] = 0
    for u in G[s]:
        par[u] = s
        dist[u] = 1
        Q.append(u)

    while Q:
        u = Q.popleft()
        for v in G[u]:
            if dist[v] != -1:
                continue
            dist[v] = dist[u] + 1
            par[v] = u
            Q.append(v)
            
    return dist

N = int(input())
s, g = map(int, input().split())
X = [s] + list(map(int, input().split())) + [g]
D = dict()
N += 2
for i in range(N):
    D[X[i]] = i
    
G = [[] for i in range(N)]
for i in range(N):
    for j in range(35):
        now = X[i] ^ (1 << j)
        if now in D:
            u = D[now]
            G[i].append(u)

DD = bfs(G, 0, N)
print(DD[-1] - 1) if DD[-1] != -1 else print(-1)
0