結果

問題 No.1576 織姫と彦星
ユーザー lloyzlloyz
提出日時 2021-12-09 23:01:41
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 536 ms / 2,000 ms
コード長 829 bytes
コンパイル時間 403 ms
コンパイル使用メモリ 10,888 KB
実行使用メモリ 8,900 KB
最終ジャッジ日時 2023-09-24 15:11:44
合計ジャッジ時間 13,572 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,660 KB
testcase_01 AC 19 ms
8,536 KB
testcase_02 AC 19 ms
8,612 KB
testcase_03 AC 19 ms
8,540 KB
testcase_04 AC 19 ms
8,548 KB
testcase_05 AC 20 ms
8,644 KB
testcase_06 AC 20 ms
8,604 KB
testcase_07 AC 126 ms
8,584 KB
testcase_08 AC 100 ms
8,596 KB
testcase_09 AC 21 ms
8,612 KB
testcase_10 AC 343 ms
8,656 KB
testcase_11 AC 21 ms
8,664 KB
testcase_12 AC 222 ms
8,736 KB
testcase_13 AC 419 ms
8,692 KB
testcase_14 AC 294 ms
8,748 KB
testcase_15 AC 311 ms
8,688 KB
testcase_16 AC 394 ms
8,616 KB
testcase_17 AC 272 ms
8,764 KB
testcase_18 AC 63 ms
8,556 KB
testcase_19 AC 96 ms
8,692 KB
testcase_20 AC 276 ms
8,568 KB
testcase_21 AC 259 ms
8,736 KB
testcase_22 AC 337 ms
8,624 KB
testcase_23 AC 48 ms
8,576 KB
testcase_24 AC 48 ms
8,576 KB
testcase_25 AC 370 ms
8,592 KB
testcase_26 AC 117 ms
8,660 KB
testcase_27 AC 24 ms
8,676 KB
testcase_28 AC 341 ms
8,632 KB
testcase_29 AC 121 ms
8,620 KB
testcase_30 AC 20 ms
8,672 KB
testcase_31 AC 131 ms
8,684 KB
testcase_32 AC 269 ms
8,788 KB
testcase_33 AC 491 ms
8,840 KB
testcase_34 AC 22 ms
8,560 KB
testcase_35 AC 159 ms
8,780 KB
testcase_36 AC 42 ms
8,612 KB
testcase_37 AC 536 ms
8,900 KB
testcase_38 AC 346 ms
8,800 KB
testcase_39 AC 204 ms
8,628 KB
testcase_40 AC 148 ms
8,592 KB
testcase_41 AC 176 ms
8,660 KB
testcase_42 AC 28 ms
8,672 KB
testcase_43 AC 57 ms
8,524 KB
testcase_44 AC 482 ms
8,740 KB
testcase_45 AC 138 ms
8,644 KB
testcase_46 AC 326 ms
8,668 KB
testcase_47 AC 66 ms
8,664 KB
testcase_48 AC 186 ms
8,792 KB
testcase_49 AC 179 ms
8,668 KB
testcase_50 AC 24 ms
8,560 KB
testcase_51 AC 45 ms
8,632 KB
testcase_52 AC 492 ms
8,628 KB
testcase_53 AC 278 ms
8,860 KB
testcase_54 AC 368 ms
8,636 KB
testcase_55 AC 473 ms
8,784 KB
testcase_56 AC 516 ms
8,660 KB
testcase_57 AC 21 ms
8,560 KB
testcase_58 AC 108 ms
8,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict, deque

n = int(input())
s, e = map(int, input().split())
A = list(map(int, input().split()))
A = [s] + A + [e]
nei_dict = defaultdict(list)
for i in range(n + 1):
    for j in range(i + 1, n + 2):
        num = A[i] ^ A[j]
        cnt = 0
        while num != 0:
            if num % 2 == 1:
                cnt += 1
                if cnt == 2:
                    break
            num //= 2
        if cnt == 1:
            nei_dict[i].append(j)
            nei_dict[j].append(i)

seen = set([0])
dq = deque([(0, 1)])
while dq:
    curr, cnt = dq.popleft()
    if curr == n + 1:
        print(cnt - 2)
        exit()
    for np in nei_dict[curr]:
        if np in seen:
            continue
        seen.add(np)
        dq.append((np, cnt + 1))
print(-1)
0