結果

問題 No.1577 織姫と彦星2
ユーザー kept1994kept1994
提出日時 2022-03-19 15:57:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 242 ms / 2,000 ms
コード長 1,345 bytes
コンパイル時間 354 ms
コンパイル使用メモリ 82,468 KB
実行使用メモリ 97,724 KB
最終ジャッジ日時 2024-04-15 05:21:39
合計ジャッジ時間 10,133 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
67,592 KB
testcase_01 AC 59 ms
68,004 KB
testcase_02 AC 60 ms
66,924 KB
testcase_03 AC 61 ms
67,720 KB
testcase_04 AC 60 ms
67,192 KB
testcase_05 AC 88 ms
80,280 KB
testcase_06 AC 69 ms
74,992 KB
testcase_07 AC 189 ms
88,888 KB
testcase_08 AC 118 ms
81,404 KB
testcase_09 AC 242 ms
97,724 KB
testcase_10 AC 106 ms
81,916 KB
testcase_11 AC 88 ms
79,088 KB
testcase_12 AC 139 ms
85,172 KB
testcase_13 AC 96 ms
80,808 KB
testcase_14 AC 153 ms
87,124 KB
testcase_15 AC 108 ms
80,288 KB
testcase_16 AC 177 ms
88,728 KB
testcase_17 AC 128 ms
83,268 KB
testcase_18 AC 65 ms
70,760 KB
testcase_19 AC 160 ms
86,848 KB
testcase_20 AC 142 ms
85,356 KB
testcase_21 AC 174 ms
88,888 KB
testcase_22 AC 169 ms
88,860 KB
testcase_23 AC 107 ms
80,804 KB
testcase_24 AC 176 ms
93,036 KB
testcase_25 AC 102 ms
80,212 KB
testcase_26 AC 110 ms
80,648 KB
testcase_27 AC 151 ms
90,420 KB
testcase_28 AC 145 ms
86,276 KB
testcase_29 AC 113 ms
84,048 KB
testcase_30 AC 125 ms
84,368 KB
testcase_31 AC 168 ms
88,792 KB
testcase_32 AC 71 ms
74,200 KB
testcase_33 AC 66 ms
71,544 KB
testcase_34 AC 113 ms
83,080 KB
testcase_35 AC 162 ms
87,172 KB
testcase_36 AC 172 ms
88,536 KB
testcase_37 AC 223 ms
96,692 KB
testcase_38 AC 222 ms
97,404 KB
testcase_39 AC 119 ms
81,388 KB
testcase_40 AC 117 ms
82,516 KB
testcase_41 AC 172 ms
91,508 KB
testcase_42 AC 129 ms
86,076 KB
testcase_43 AC 129 ms
86,220 KB
testcase_44 AC 69 ms
74,276 KB
testcase_45 AC 99 ms
79,456 KB
testcase_46 AC 93 ms
80,248 KB
testcase_47 AC 137 ms
91,472 KB
testcase_48 AC 108 ms
82,740 KB
testcase_49 AC 125 ms
83,204 KB
testcase_50 AC 106 ms
80,772 KB
testcase_51 AC 72 ms
75,360 KB
testcase_52 AC 183 ms
92,900 KB
testcase_53 AC 187 ms
93,188 KB
testcase_54 AC 120 ms
84,288 KB
testcase_55 AC 177 ms
92,940 KB
testcase_56 AC 106 ms
80,340 KB
testcase_57 AC 93 ms
79,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3

from bz2 import compress


def main():
    import math
    from collections import deque
    INF = 10 ** 16
    def bfs(edges: "List[to]", start_node: int) -> list:
        q = deque()
        dist = [INF] * len(edges)
        q.append(start_node)
        dist[start_node] = 0
        while q:
            now = q.popleft()
            for next in edges[now]:
                if dist[next] != INF:
                    continue
                q.append(next)
                dist[next] = dist[now] + 1
        return dist
    N = int(input())
    st, ed = map(int, input().split())
    stones = [st] + list(map(int, input().split())) + [ed]
    compressed = {}
    compressed_to_row = []
    routes = set(stones)
    for index, val in enumerate(sorted(list(routes))):
        compressed[val] = index
        compressed_to_row.append(val)
    # print(compressed)
    G = [[] for _ in range(N + 2)]
    for i in range(N + 2):
        for b in range(30):
            reachable = stones[i] ^ 1 << b
            if reachable in routes:
                G[compressed[stones[i]]].append(compressed[reachable])
                G[compressed[reachable]].append(compressed[stones[i]])
    d = bfs(G, compressed[st])
    print(d[compressed[ed]] - 1 if d[compressed[ed]] != INF else -1)
    return

if __name__ == '__main__':
    main()
0