結果

問題 No.1576 織姫と彦星
ユーザー y05h1k1ngy05h1k1ng
提出日時 2021-07-01 12:48:00
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 433 ms / 2,000 ms
コード長 639 bytes
コンパイル時間 182 ms
コンパイル使用メモリ 10,888 KB
実行使用メモリ 8,788 KB
最終ジャッジ日時 2023-09-10 10:28:54
合計ジャッジ時間 8,998 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
8,484 KB
testcase_01 AC 20 ms
8,640 KB
testcase_02 AC 19 ms
8,568 KB
testcase_03 AC 19 ms
8,508 KB
testcase_04 AC 18 ms
8,496 KB
testcase_05 AC 19 ms
8,592 KB
testcase_06 AC 19 ms
8,488 KB
testcase_07 AC 65 ms
8,688 KB
testcase_08 AC 35 ms
8,548 KB
testcase_09 AC 20 ms
8,656 KB
testcase_10 AC 250 ms
8,644 KB
testcase_11 AC 20 ms
8,616 KB
testcase_12 AC 145 ms
8,560 KB
testcase_13 AC 144 ms
8,592 KB
testcase_14 AC 224 ms
8,552 KB
testcase_15 AC 200 ms
8,552 KB
testcase_16 AC 114 ms
8,600 KB
testcase_17 AC 163 ms
8,552 KB
testcase_18 AC 46 ms
8,576 KB
testcase_19 AC 83 ms
8,640 KB
testcase_20 AC 21 ms
8,760 KB
testcase_21 AC 180 ms
8,656 KB
testcase_22 AC 53 ms
8,668 KB
testcase_23 AC 25 ms
8,532 KB
testcase_24 AC 37 ms
8,612 KB
testcase_25 AC 158 ms
8,588 KB
testcase_26 AC 106 ms
8,564 KB
testcase_27 AC 20 ms
8,516 KB
testcase_28 AC 153 ms
8,664 KB
testcase_29 AC 104 ms
8,636 KB
testcase_30 AC 19 ms
8,524 KB
testcase_31 AC 95 ms
8,704 KB
testcase_32 AC 154 ms
8,724 KB
testcase_33 AC 402 ms
8,612 KB
testcase_34 AC 19 ms
8,488 KB
testcase_35 AC 131 ms
8,568 KB
testcase_36 AC 36 ms
8,592 KB
testcase_37 AC 433 ms
8,752 KB
testcase_38 AC 209 ms
8,664 KB
testcase_39 AC 160 ms
8,552 KB
testcase_40 AC 109 ms
8,616 KB
testcase_41 AC 135 ms
8,568 KB
testcase_42 AC 25 ms
8,624 KB
testcase_43 AC 45 ms
8,620 KB
testcase_44 AC 421 ms
8,672 KB
testcase_45 AC 79 ms
8,652 KB
testcase_46 AC 272 ms
8,672 KB
testcase_47 AC 23 ms
8,724 KB
testcase_48 AC 160 ms
8,712 KB
testcase_49 AC 141 ms
8,660 KB
testcase_50 AC 22 ms
8,664 KB
testcase_51 AC 23 ms
8,520 KB
testcase_52 AC 45 ms
8,740 KB
testcase_53 AC 252 ms
8,580 KB
testcase_54 AC 178 ms
8,592 KB
testcase_55 AC 198 ms
8,788 KB
testcase_56 AC 207 ms
8,768 KB
testcase_57 AC 20 ms
8,600 KB
testcase_58 AC 65 ms
8,644 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

def hamming_distance(a: int, b: int) -> int:
    x = a ^ b
    return bin(x)[2:].count("1")

n = int(input())
start, end = map(int, input().split(" "))
stones = list(map(int, input().split(" ")))
visited = [False] * n

que = deque([])
que.append((0, start))

while len(que):
    cnt, now = que.popleft()

    if hamming_distance(now, end) == 1:
        print(cnt)
        break

    for i in range(n):
        stone = stones[i]
        if visited[i]:
            continue
        if hamming_distance(now, stone) == 1:
            visited[i] = True
            que.append((cnt+1, stone))

else:
    print(-1)
0