結果

問題 No.1576 織姫と彦星
ユーザー ああいいああいい
提出日時 2021-12-23 19:17:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 228 ms / 2,000 ms
コード長 743 bytes
コンパイル時間 653 ms
コンパイル使用メモリ 81,744 KB
実行使用メモリ 76,076 KB
最終ジャッジ日時 2023-10-17 20:37:48
合計ジャッジ時間 9,415 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
55,572 KB
testcase_01 AC 42 ms
55,576 KB
testcase_02 AC 43 ms
55,576 KB
testcase_03 AC 43 ms
55,576 KB
testcase_04 AC 42 ms
55,576 KB
testcase_05 AC 49 ms
61,052 KB
testcase_06 AC 50 ms
61,120 KB
testcase_07 AC 96 ms
75,496 KB
testcase_08 AC 87 ms
75,516 KB
testcase_09 AC 55 ms
64,072 KB
testcase_10 AC 172 ms
75,672 KB
testcase_11 AC 58 ms
66,148 KB
testcase_12 AC 122 ms
75,708 KB
testcase_13 AC 202 ms
75,828 KB
testcase_14 AC 141 ms
75,728 KB
testcase_15 AC 140 ms
75,656 KB
testcase_16 AC 179 ms
75,560 KB
testcase_17 AC 149 ms
75,708 KB
testcase_18 AC 73 ms
75,512 KB
testcase_19 AC 86 ms
75,696 KB
testcase_20 AC 150 ms
75,540 KB
testcase_21 AC 142 ms
75,720 KB
testcase_22 AC 163 ms
75,552 KB
testcase_23 AC 72 ms
75,512 KB
testcase_24 AC 74 ms
75,532 KB
testcase_25 AC 171 ms
75,716 KB
testcase_26 AC 92 ms
75,880 KB
testcase_27 AC 57 ms
68,196 KB
testcase_28 AC 168 ms
75,716 KB
testcase_29 AC 96 ms
75,640 KB
testcase_30 AC 50 ms
61,200 KB
testcase_31 AC 98 ms
75,684 KB
testcase_32 AC 138 ms
75,712 KB
testcase_33 AC 219 ms
75,788 KB
testcase_34 AC 58 ms
66,148 KB
testcase_35 AC 110 ms
75,708 KB
testcase_36 AC 69 ms
75,260 KB
testcase_37 AC 213 ms
75,756 KB
testcase_38 AC 156 ms
75,664 KB
testcase_39 AC 115 ms
75,708 KB
testcase_40 AC 103 ms
75,716 KB
testcase_41 AC 112 ms
75,708 KB
testcase_42 AC 59 ms
68,188 KB
testcase_43 AC 75 ms
75,520 KB
testcase_44 AC 200 ms
75,784 KB
testcase_45 AC 101 ms
75,548 KB
testcase_46 AC 228 ms
75,764 KB
testcase_47 AC 76 ms
75,516 KB
testcase_48 AC 112 ms
75,696 KB
testcase_49 AC 113 ms
75,708 KB
testcase_50 AC 56 ms
66,168 KB
testcase_51 AC 70 ms
75,512 KB
testcase_52 AC 199 ms
75,560 KB
testcase_53 AC 153 ms
76,076 KB
testcase_54 AC 169 ms
75,656 KB
testcase_55 AC 211 ms
75,720 KB
testcase_56 AC 227 ms
75,724 KB
testcase_57 AC 54 ms
64,068 KB
testcase_58 AC 90 ms
75,524 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
s,e = map(int,input().split())
l = list(map(int,input().split()))
l.insert(0,s)
l.append(e)
C = 10 ** 5
memo = [C] * (N + 2)
memo[0] = 0

def hamu(a,b):
    count = 0
    while a != 0 or b != 0:
        if a & 1 != b & 1:
            count += 1
        a >>= 1
        b >>= 1
    return count < 2
G = [[] for _ in range(N + 2)]
for i in range(N+1):
    for j in range(i + 1,N + 2):
        if hamu(l[i],l[j]):
            G[i].append(j)
            G[j].append(i)
    
from collections import deque
q = deque()
q.append(0)
while len(q):
    now = q.popleft()
    for v in G[now]:
        if memo[v] == C:
            memo[v] = memo[now] + 1
            q.append(v)
if memo[-1] == C:
    print(-1)
else:
    print(memo[-1]-1)
0