結果

問題 No.1576 織姫と彦星
ユーザー lloyzlloyz
提出日時 2021-12-09 23:01:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 139 ms / 2,000 ms
コード長 795 bytes
コンパイル時間 264 ms
コンパイル使用メモリ 86,932 KB
実行使用メモリ 78,104 KB
最終ジャッジ日時 2023-09-24 15:10:45
合計ジャッジ時間 10,036 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
71,804 KB
testcase_01 AC 93 ms
71,576 KB
testcase_02 AC 90 ms
71,588 KB
testcase_03 AC 92 ms
71,344 KB
testcase_04 AC 92 ms
71,636 KB
testcase_05 AC 92 ms
71,728 KB
testcase_06 AC 99 ms
76,988 KB
testcase_07 AC 110 ms
77,840 KB
testcase_08 AC 110 ms
77,564 KB
testcase_09 AC 100 ms
76,948 KB
testcase_10 AC 127 ms
77,820 KB
testcase_11 AC 101 ms
77,052 KB
testcase_12 AC 122 ms
78,068 KB
testcase_13 AC 128 ms
77,824 KB
testcase_14 AC 123 ms
77,576 KB
testcase_15 AC 125 ms
77,836 KB
testcase_16 AC 127 ms
77,784 KB
testcase_17 AC 120 ms
77,636 KB
testcase_18 AC 106 ms
77,596 KB
testcase_19 AC 113 ms
77,940 KB
testcase_20 AC 117 ms
77,836 KB
testcase_21 AC 122 ms
77,656 KB
testcase_22 AC 124 ms
77,680 KB
testcase_23 AC 107 ms
77,364 KB
testcase_24 AC 106 ms
77,368 KB
testcase_25 AC 126 ms
77,908 KB
testcase_26 AC 115 ms
77,844 KB
testcase_27 AC 104 ms
77,036 KB
testcase_28 AC 124 ms
78,104 KB
testcase_29 AC 116 ms
77,804 KB
testcase_30 AC 103 ms
76,900 KB
testcase_31 AC 115 ms
77,620 KB
testcase_32 AC 122 ms
77,768 KB
testcase_33 AC 137 ms
77,800 KB
testcase_34 AC 104 ms
76,936 KB
testcase_35 AC 123 ms
77,548 KB
testcase_36 AC 106 ms
77,408 KB
testcase_37 AC 139 ms
77,864 KB
testcase_38 AC 126 ms
77,956 KB
testcase_39 AC 119 ms
77,744 KB
testcase_40 AC 116 ms
77,740 KB
testcase_41 AC 119 ms
77,656 KB
testcase_42 AC 102 ms
77,020 KB
testcase_43 AC 106 ms
77,468 KB
testcase_44 AC 133 ms
77,780 KB
testcase_45 AC 113 ms
77,592 KB
testcase_46 AC 129 ms
77,768 KB
testcase_47 AC 109 ms
77,584 KB
testcase_48 AC 117 ms
77,712 KB
testcase_49 AC 116 ms
77,700 KB
testcase_50 AC 101 ms
76,908 KB
testcase_51 AC 106 ms
77,672 KB
testcase_52 AC 127 ms
77,284 KB
testcase_53 AC 125 ms
77,836 KB
testcase_54 AC 126 ms
77,780 KB
testcase_55 AC 131 ms
77,720 KB
testcase_56 AC 131 ms
77,792 KB
testcase_57 AC 101 ms
77,072 KB
testcase_58 AC 109 ms
77,500 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