結果

問題 No.1577 織姫と彦星2
ユーザー ああいいああいい
提出日時 2021-12-28 20:11:51
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 482 ms / 2,000 ms
コード長 521 bytes
コンパイル時間 181 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 19,324 KB
最終ジャッジ日時 2024-04-10 12:28:08
合計ジャッジ時間 10,175 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
10,624 KB
testcase_01 AC 28 ms
10,624 KB
testcase_02 AC 29 ms
10,624 KB
testcase_03 AC 31 ms
10,752 KB
testcase_04 AC 30 ms
10,752 KB
testcase_05 AC 34 ms
12,800 KB
testcase_06 AC 29 ms
11,392 KB
testcase_07 AC 72 ms
16,432 KB
testcase_08 AC 150 ms
13,496 KB
testcase_09 AC 289 ms
18,620 KB
testcase_10 AC 69 ms
13,280 KB
testcase_11 AC 44 ms
11,264 KB
testcase_12 AC 154 ms
16,072 KB
testcase_13 AC 45 ms
12,800 KB
testcase_14 AC 220 ms
16,616 KB
testcase_15 AC 126 ms
12,928 KB
testcase_16 AC 248 ms
18,464 KB
testcase_17 AC 150 ms
15,508 KB
testcase_18 AC 30 ms
10,752 KB
testcase_19 AC 293 ms
18,724 KB
testcase_20 AC 275 ms
18,060 KB
testcase_21 AC 352 ms
18,668 KB
testcase_22 AC 251 ms
19,220 KB
testcase_23 AC 151 ms
13,424 KB
testcase_24 AC 225 ms
17,468 KB
testcase_25 AC 87 ms
12,800 KB
testcase_26 AC 156 ms
13,232 KB
testcase_27 AC 81 ms
16,664 KB
testcase_28 AC 203 ms
16,788 KB
testcase_29 AC 85 ms
15,540 KB
testcase_30 AC 150 ms
15,924 KB
testcase_31 AC 263 ms
18,168 KB
testcase_32 AC 32 ms
10,880 KB
testcase_33 AC 34 ms
10,880 KB
testcase_34 AC 113 ms
15,488 KB
testcase_35 AC 258 ms
18,860 KB
testcase_36 AC 303 ms
19,324 KB
testcase_37 AC 482 ms
18,912 KB
testcase_38 AC 197 ms
17,376 KB
testcase_39 AC 119 ms
13,452 KB
testcase_40 AC 128 ms
13,492 KB
testcase_41 AC 101 ms
17,032 KB
testcase_42 AC 79 ms
16,480 KB
testcase_43 AC 90 ms
16,640 KB
testcase_44 AC 33 ms
10,880 KB
testcase_45 AC 86 ms
12,544 KB
testcase_46 AC 52 ms
12,544 KB
testcase_47 AC 70 ms
17,128 KB
testcase_48 AC 58 ms
13,280 KB
testcase_49 AC 123 ms
15,524 KB
testcase_50 AC 62 ms
12,800 KB
testcase_51 AC 33 ms
11,264 KB
testcase_52 AC 243 ms
19,232 KB
testcase_53 AC 241 ms
17,336 KB
testcase_54 AC 92 ms
15,836 KB
testcase_55 AC 241 ms
17,432 KB
testcase_56 AC 132 ms
13,056 KB
testcase_57 AC 53 ms
12,032 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
start ,end = map(int,input().split())
stone = set(list(map(int,input().split())))

s = set()
from collections import deque
import sys
q = deque()
q.append((start,0))
s.add(start)

m = max(stone)
k = 1
while 1 << k <= m:
    k += 1
while len(q):
    now,d = q.popleft()
    for j in range(k):
        next = now ^ (1 << j)
        if next == end:
            print(d)
            exit()
        if next in stone and next not in s:
            s.add(next)
            q.append((next,d + 1))
print(-1)
    
0