結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
9,628 KB
testcase_01 AC 26 ms
9,628 KB
testcase_02 AC 25 ms
9,504 KB
testcase_03 AC 25 ms
9,492 KB
testcase_04 AC 25 ms
9,500 KB
testcase_05 AC 30 ms
11,648 KB
testcase_06 AC 28 ms
10,012 KB
testcase_07 AC 64 ms
15,376 KB
testcase_08 AC 109 ms
12,608 KB
testcase_09 AC 263 ms
19,152 KB
testcase_10 AC 56 ms
11,916 KB
testcase_11 AC 39 ms
10,156 KB
testcase_12 AC 113 ms
14,940 KB
testcase_13 AC 38 ms
11,712 KB
testcase_14 AC 160 ms
15,796 KB
testcase_15 AC 97 ms
11,932 KB
testcase_16 AC 189 ms
17,456 KB
testcase_17 AC 130 ms
14,504 KB
testcase_18 AC 26 ms
9,716 KB
testcase_19 AC 219 ms
17,920 KB
testcase_20 AC 204 ms
17,136 KB
testcase_21 AC 258 ms
17,704 KB
testcase_22 AC 187 ms
17,288 KB
testcase_23 AC 109 ms
12,288 KB
testcase_24 AC 170 ms
16,100 KB
testcase_25 AC 68 ms
11,816 KB
testcase_26 AC 112 ms
12,240 KB
testcase_27 AC 66 ms
15,428 KB
testcase_28 AC 159 ms
15,504 KB
testcase_29 AC 69 ms
14,576 KB
testcase_30 AC 113 ms
14,560 KB
testcase_31 AC 188 ms
17,516 KB
testcase_32 AC 28 ms
9,864 KB
testcase_33 AC 30 ms
9,772 KB
testcase_34 AC 86 ms
14,264 KB
testcase_35 AC 194 ms
17,860 KB
testcase_36 AC 214 ms
17,460 KB
testcase_37 AC 369 ms
17,288 KB
testcase_38 AC 148 ms
16,040 KB
testcase_39 AC 95 ms
12,368 KB
testcase_40 AC 99 ms
12,772 KB
testcase_41 AC 82 ms
15,956 KB
testcase_42 AC 62 ms
15,488 KB
testcase_43 AC 70 ms
15,568 KB
testcase_44 AC 29 ms
9,880 KB
testcase_45 AC 65 ms
11,504 KB
testcase_46 AC 43 ms
11,336 KB
testcase_47 AC 57 ms
15,992 KB
testcase_48 AC 49 ms
12,160 KB
testcase_49 AC 93 ms
14,240 KB
testcase_50 AC 50 ms
11,568 KB
testcase_51 AC 28 ms
10,108 KB
testcase_52 AC 196 ms
18,980 KB
testcase_53 AC 183 ms
16,096 KB
testcase_54 AC 74 ms
13,564 KB
testcase_55 AC 176 ms
16,192 KB
testcase_56 AC 102 ms
12,036 KB
testcase_57 AC 46 ms
10,868 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