結果

問題 No.1576 織姫と彦星
ユーザー k1832k1832
提出日時 2021-06-19 00:10:36
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 274 ms / 2,000 ms
コード長 792 bytes
コンパイル時間 153 ms
コンパイル使用メモリ 11,004 KB
実行使用メモリ 9,260 KB
最終ジャッジ日時 2023-09-05 01:05:02
合計ジャッジ時間 7,018 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
8,976 KB
testcase_01 AC 23 ms
8,940 KB
testcase_02 AC 22 ms
9,008 KB
testcase_03 AC 22 ms
9,024 KB
testcase_04 AC 22 ms
9,100 KB
testcase_05 AC 23 ms
9,068 KB
testcase_06 AC 23 ms
9,044 KB
testcase_07 AC 53 ms
9,072 KB
testcase_08 AC 33 ms
9,136 KB
testcase_09 AC 24 ms
9,016 KB
testcase_10 AC 166 ms
9,096 KB
testcase_11 AC 23 ms
9,120 KB
testcase_12 AC 101 ms
9,216 KB
testcase_13 AC 105 ms
9,052 KB
testcase_14 AC 146 ms
9,200 KB
testcase_15 AC 133 ms
9,148 KB
testcase_16 AC 82 ms
9,212 KB
testcase_17 AC 117 ms
9,180 KB
testcase_18 AC 40 ms
9,160 KB
testcase_19 AC 61 ms
9,140 KB
testcase_20 AC 25 ms
9,192 KB
testcase_21 AC 123 ms
9,260 KB
testcase_22 AC 45 ms
9,060 KB
testcase_23 AC 27 ms
9,076 KB
testcase_24 AC 35 ms
8,984 KB
testcase_25 AC 112 ms
9,124 KB
testcase_26 AC 74 ms
9,064 KB
testcase_27 AC 23 ms
9,152 KB
testcase_28 AC 108 ms
9,088 KB
testcase_29 AC 74 ms
9,112 KB
testcase_30 AC 22 ms
9,096 KB
testcase_31 AC 72 ms
9,024 KB
testcase_32 AC 112 ms
9,200 KB
testcase_33 AC 255 ms
9,228 KB
testcase_34 AC 23 ms
9,032 KB
testcase_35 AC 92 ms
9,260 KB
testcase_36 AC 33 ms
9,124 KB
testcase_37 AC 274 ms
9,248 KB
testcase_38 AC 137 ms
9,240 KB
testcase_39 AC 110 ms
9,056 KB
testcase_40 AC 77 ms
9,152 KB
testcase_41 AC 93 ms
9,080 KB
testcase_42 AC 26 ms
9,048 KB
testcase_43 AC 40 ms
8,980 KB
testcase_44 AC 267 ms
9,160 KB
testcase_45 AC 61 ms
9,092 KB
testcase_46 AC 177 ms
9,260 KB
testcase_47 AC 26 ms
9,072 KB
testcase_48 AC 112 ms
9,116 KB
testcase_49 AC 98 ms
9,216 KB
testcase_50 AC 25 ms
8,984 KB
testcase_51 AC 26 ms
9,124 KB
testcase_52 AC 40 ms
9,120 KB
testcase_53 AC 159 ms
9,236 KB
testcase_54 AC 127 ms
9,112 KB
testcase_55 AC 133 ms
9,136 KB
testcase_56 AC 141 ms
9,080 KB
testcase_57 AC 23 ms
8,976 KB
testcase_58 AC 51 ms
9,172 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import queue
def get_hd(a,b):
    return bin(a^b).count('1')

def solve_slower(start, end, stones):
    checked_set = set()
    que = queue.Queue()
    que.put((start, 0))
    while not que.empty():
        current, distance = que.get()
        next_distance = distance + 1
        if get_hd(current, end) == 1:
            return next_distance - 1
        for candidate in stones:
            if candidate in checked_set:
                continue
            if get_hd(current, candidate) == 1:
                checked_set.add(candidate)
                que.put((candidate, next_distance))
    return -1

if __name__ == '__main__':
    N = int(input())
    start, end = list(map(int, input().split()))
    stones = list(map(int, input().split()))
    print(solve_slower(start, end, stones))
0