結果

問題 No.1577 織姫と彦星2
ユーザー k1832k1832
提出日時 2021-06-19 00:22:59
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 357 ms / 2,000 ms
コード長 777 bytes
コンパイル時間 180 ms
コンパイル使用メモリ 10,880 KB
実行使用メモリ 19,204 KB
最終ジャッジ日時 2023-09-05 01:05:20
合計ジャッジ時間 8,518 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
9,652 KB
testcase_01 AC 26 ms
9,692 KB
testcase_02 AC 25 ms
9,524 KB
testcase_03 AC 25 ms
9,468 KB
testcase_04 AC 24 ms
9,676 KB
testcase_05 AC 30 ms
11,684 KB
testcase_06 AC 26 ms
10,000 KB
testcase_07 AC 56 ms
15,168 KB
testcase_08 AC 110 ms
12,540 KB
testcase_09 AC 256 ms
19,204 KB
testcase_10 AC 55 ms
11,828 KB
testcase_11 AC 37 ms
10,052 KB
testcase_12 AC 112 ms
14,796 KB
testcase_13 AC 37 ms
11,708 KB
testcase_14 AC 160 ms
15,604 KB
testcase_15 AC 95 ms
11,876 KB
testcase_16 AC 188 ms
17,364 KB
testcase_17 AC 126 ms
14,632 KB
testcase_18 AC 26 ms
9,584 KB
testcase_19 AC 219 ms
17,860 KB
testcase_20 AC 202 ms
16,968 KB
testcase_21 AC 255 ms
17,840 KB
testcase_22 AC 184 ms
17,412 KB
testcase_23 AC 108 ms
12,108 KB
testcase_24 AC 170 ms
16,144 KB
testcase_25 AC 67 ms
11,912 KB
testcase_26 AC 111 ms
12,148 KB
testcase_27 AC 65 ms
15,540 KB
testcase_28 AC 154 ms
15,456 KB
testcase_29 AC 66 ms
14,568 KB
testcase_30 AC 108 ms
14,656 KB
testcase_31 AC 182 ms
17,384 KB
testcase_32 AC 28 ms
9,980 KB
testcase_33 AC 29 ms
9,668 KB
testcase_34 AC 87 ms
14,116 KB
testcase_35 AC 187 ms
17,656 KB
testcase_36 AC 212 ms
17,400 KB
testcase_37 AC 357 ms
17,356 KB
testcase_38 AC 145 ms
16,008 KB
testcase_39 AC 93 ms
12,376 KB
testcase_40 AC 98 ms
12,780 KB
testcase_41 AC 80 ms
15,968 KB
testcase_42 AC 61 ms
15,412 KB
testcase_43 AC 69 ms
15,464 KB
testcase_44 AC 28 ms
9,952 KB
testcase_45 AC 65 ms
11,656 KB
testcase_46 AC 42 ms
11,316 KB
testcase_47 AC 55 ms
16,040 KB
testcase_48 AC 49 ms
12,020 KB
testcase_49 AC 91 ms
14,404 KB
testcase_50 AC 50 ms
11,560 KB
testcase_51 AC 28 ms
10,152 KB
testcase_52 AC 189 ms
18,948 KB
testcase_53 AC 177 ms
16,120 KB
testcase_54 AC 72 ms
14,852 KB
testcase_55 AC 173 ms
16,028 KB
testcase_56 AC 101 ms
11,952 KB
testcase_57 AC 43 ms
10,908 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import random
import queue
def solve(start, end, stones):
    stone_set = set(stones)
    checked_set = set()
    que = queue.Queue()
    que.put((start, 0))
    while not que.empty():
        current, distance = que.get()
        next_distance = distance + 1
        for i in range(31):
            candidate = current ^ (1<<i)
            if candidate == end:
                return next_distance - 1
            
            if candidate in stone_set and candidate not in checked_set:
                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(start, end, stones))
0