結果

問題 No.1576 織姫と彦星
ユーザー kept1994kept1994
提出日時 2022-03-19 15:40:32
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 73 ms / 2,000 ms
コード長 1,001 bytes
コンパイル時間 158 ms
コンパイル使用メモリ 82,248 KB
実行使用メモリ 66,584 KB
最終ジャッジ日時 2024-04-15 05:02:40
合計ジャッジ時間 4,942 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
55,704 KB
testcase_01 AC 40 ms
55,440 KB
testcase_02 AC 39 ms
54,652 KB
testcase_03 AC 38 ms
56,052 KB
testcase_04 AC 38 ms
55,676 KB
testcase_05 AC 40 ms
54,960 KB
testcase_06 AC 40 ms
55,104 KB
testcase_07 AC 50 ms
62,488 KB
testcase_08 AC 48 ms
62,908 KB
testcase_09 AC 43 ms
61,636 KB
testcase_10 AC 66 ms
63,644 KB
testcase_11 AC 43 ms
61,780 KB
testcase_12 AC 55 ms
63,024 KB
testcase_13 AC 66 ms
63,520 KB
testcase_14 AC 60 ms
64,924 KB
testcase_15 AC 58 ms
63,576 KB
testcase_16 AC 63 ms
62,296 KB
testcase_17 AC 60 ms
63,240 KB
testcase_18 AC 47 ms
63,168 KB
testcase_19 AC 49 ms
63,032 KB
testcase_20 AC 56 ms
63,956 KB
testcase_21 AC 57 ms
64,104 KB
testcase_22 AC 59 ms
62,708 KB
testcase_23 AC 45 ms
62,640 KB
testcase_24 AC 45 ms
62,564 KB
testcase_25 AC 63 ms
63,648 KB
testcase_26 AC 52 ms
63,872 KB
testcase_27 AC 43 ms
62,096 KB
testcase_28 AC 59 ms
62,600 KB
testcase_29 AC 49 ms
63,224 KB
testcase_30 AC 40 ms
56,252 KB
testcase_31 AC 50 ms
62,792 KB
testcase_32 AC 59 ms
63,096 KB
testcase_33 AC 73 ms
66,584 KB
testcase_34 AC 43 ms
61,168 KB
testcase_35 AC 51 ms
63,572 KB
testcase_36 AC 44 ms
62,044 KB
testcase_37 AC 73 ms
64,924 KB
testcase_38 AC 62 ms
63,692 KB
testcase_39 AC 56 ms
62,764 KB
testcase_40 AC 54 ms
62,900 KB
testcase_41 AC 53 ms
62,760 KB
testcase_42 AC 42 ms
62,584 KB
testcase_43 AC 45 ms
62,580 KB
testcase_44 AC 68 ms
64,532 KB
testcase_45 AC 47 ms
62,412 KB
testcase_46 AC 63 ms
64,920 KB
testcase_47 AC 46 ms
62,256 KB
testcase_48 AC 53 ms
62,968 KB
testcase_49 AC 53 ms
63,568 KB
testcase_50 AC 42 ms
62,124 KB
testcase_51 AC 45 ms
61,484 KB
testcase_52 AC 65 ms
63,768 KB
testcase_53 AC 59 ms
65,508 KB
testcase_54 AC 62 ms
62,828 KB
testcase_55 AC 67 ms
63,628 KB
testcase_56 AC 70 ms
64,208 KB
testcase_57 AC 42 ms
60,856 KB
testcase_58 AC 48 ms
61,936 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3

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]
    G = [[] for _ in range(N + 2)]
    for i in range(N + 1):
        for j in range(i + 1, N + 2):
            w = stones[i] ^ stones[j]
            if w == 0 or math.log2(w).is_integer():
                G[i].append(j)
                G[j].append(i)
    d = bfs(G, 0)
    print(d[-1] - 1 if d[-1] != INF else -1)
    return

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