結果

問題 No.1576 織姫と彦星
ユーザー ああいいああいい
提出日時 2021-12-23 19:16:55
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 743 bytes
コンパイル時間 446 ms
コンパイル使用メモリ 11,988 KB
実行使用メモリ 10,360 KB
最終ジャッジ日時 2023-10-17 20:36:29
合計ジャッジ時間 45,096 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,128 KB
testcase_01 AC 29 ms
10,128 KB
testcase_02 AC 29 ms
10,128 KB
testcase_03 AC 30 ms
10,128 KB
testcase_04 AC 30 ms
10,128 KB
testcase_05 AC 30 ms
10,128 KB
testcase_06 AC 33 ms
10,128 KB
testcase_07 AC 510 ms
10,188 KB
testcase_08 AC 371 ms
10,176 KB
testcase_09 AC 38 ms
10,132 KB
testcase_10 AC 1,435 ms
10,268 KB
testcase_11 AC 40 ms
10,132 KB
testcase_12 AC 849 ms
10,228 KB
testcase_13 AC 1,853 ms
10,252 KB
testcase_14 AC 1,142 ms
10,268 KB
testcase_15 AC 1,124 ms
10,260 KB
testcase_16 AC 1,506 ms
10,244 KB
testcase_17 AC 1,162 ms
10,252 KB
testcase_18 AC 185 ms
10,156 KB
testcase_19 AC 341 ms
10,176 KB
testcase_20 AC 1,211 ms
10,224 KB
testcase_21 AC 1,060 ms
10,252 KB
testcase_22 AC 1,345 ms
10,236 KB
testcase_23 AC 149 ms
10,148 KB
testcase_24 AC 141 ms
10,148 KB
testcase_25 AC 1,593 ms
10,248 KB
testcase_26 AC 441 ms
10,204 KB
testcase_27 AC 51 ms
10,132 KB
testcase_28 AC 1,360 ms
10,248 KB
testcase_29 AC 441 ms
10,208 KB
testcase_30 AC 32 ms
10,128 KB
testcase_31 AC 508 ms
10,196 KB
testcase_32 AC 1,091 ms
10,244 KB
testcase_33 TLE -
testcase_34 AC 41 ms
10,132 KB
testcase_35 AC 606 ms
10,220 KB
testcase_36 AC 120 ms
10,148 KB
testcase_37 TLE -
testcase_38 AC 1,357 ms
10,260 KB
testcase_39 AC 738 ms
10,228 KB
testcase_40 AC 534 ms
10,200 KB
testcase_41 AC 629 ms
10,216 KB
testcase_42 AC 56 ms
10,136 KB
testcase_43 AC 189 ms
10,156 KB
testcase_44 AC 1,956 ms
10,320 KB
testcase_45 AC 519 ms
10,192 KB
testcase_46 AC 1,237 ms
10,284 KB
testcase_47 AC 231 ms
10,152 KB
testcase_48 AC 731 ms
10,228 KB
testcase_49 AC 673 ms
10,220 KB
testcase_50 AC 48 ms
10,136 KB
testcase_51 AC 145 ms
10,144 KB
testcase_52 TLE -
testcase_53 AC 1,121 ms
10,280 KB
testcase_54 AC 1,534 ms
10,252 KB
testcase_55 AC 1,911 ms
10,260 KB
testcase_56 TLE -
testcase_57 AC 36 ms
10,128 KB
testcase_58 AC 401 ms
10,184 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