結果

問題 No.1576 織姫と彦星
ユーザー wgrapewgrape
提出日時 2023-11-01 09:37:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,066 ms / 2,000 ms
コード長 875 bytes
コンパイル時間 474 ms
コンパイル使用メモリ 81,836 KB
実行使用メモリ 76,884 KB
最終ジャッジ日時 2023-11-01 09:37:35
合計ジャッジ時間 27,557 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
55,544 KB
testcase_01 AC 43 ms
55,544 KB
testcase_02 AC 41 ms
55,544 KB
testcase_03 AC 42 ms
55,544 KB
testcase_04 AC 41 ms
55,544 KB
testcase_05 AC 51 ms
55,544 KB
testcase_06 AC 52 ms
63,816 KB
testcase_07 AC 324 ms
76,264 KB
testcase_08 AC 242 ms
76,648 KB
testcase_09 AC 80 ms
76,188 KB
testcase_10 AC 723 ms
76,884 KB
testcase_11 AC 87 ms
76,252 KB
testcase_12 AC 450 ms
76,476 KB
testcase_13 AC 893 ms
76,328 KB
testcase_14 AC 584 ms
76,544 KB
testcase_15 AC 599 ms
76,396 KB
testcase_16 AC 748 ms
76,324 KB
testcase_17 AC 608 ms
76,548 KB
testcase_18 AC 164 ms
76,232 KB
testcase_19 AC 232 ms
76,516 KB
testcase_20 AC 589 ms
76,624 KB
testcase_21 AC 537 ms
76,444 KB
testcase_22 AC 656 ms
76,528 KB
testcase_23 AC 144 ms
76,416 KB
testcase_24 AC 143 ms
76,184 KB
testcase_25 AC 785 ms
76,312 KB
testcase_26 AC 275 ms
76,376 KB
testcase_27 AC 99 ms
76,468 KB
testcase_28 AC 705 ms
76,524 KB
testcase_29 AC 275 ms
76,540 KB
testcase_30 AC 51 ms
63,404 KB
testcase_31 AC 300 ms
76,536 KB
testcase_32 AC 574 ms
76,300 KB
testcase_33 AC 985 ms
76,624 KB
testcase_34 AC 88 ms
76,320 KB
testcase_35 AC 349 ms
76,408 KB
testcase_36 AC 135 ms
76,500 KB
testcase_37 AC 1,066 ms
76,388 KB
testcase_38 AC 695 ms
76,564 KB
testcase_39 AC 408 ms
76,296 KB
testcase_40 AC 318 ms
76,524 KB
testcase_41 AC 363 ms
76,280 KB
testcase_42 AC 112 ms
76,712 KB
testcase_43 AC 166 ms
76,436 KB
testcase_44 AC 922 ms
76,800 KB
testcase_45 AC 310 ms
76,800 KB
testcase_46 AC 623 ms
76,388 KB
testcase_47 AC 184 ms
76,612 KB
testcase_48 AC 421 ms
76,496 KB
testcase_49 AC 372 ms
76,560 KB
testcase_50 AC 104 ms
76,392 KB
testcase_51 AC 140 ms
76,372 KB
testcase_52 AC 964 ms
76,448 KB
testcase_53 AC 591 ms
76,740 KB
testcase_54 AC 736 ms
76,560 KB
testcase_55 AC 946 ms
76,292 KB
testcase_56 AC 1,031 ms
76,316 KB
testcase_57 AC 68 ms
73,932 KB
testcase_58 AC 255 ms
76,616 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
s,e = map(int,input().split())
S = [s] + list(map(int,input().split())) + [e]
N += 2

def check(X, Y):
    L = len(bin(max(X,Y))[2:])
    X = bin(X)[2:].zfill(L)
    Y = bin(Y)[2:].zfill(L)
    cnt = 0
    for i in range(L):
        if X[i] != Y[i]:
            cnt += 1
            if cnt > 1:
                return False
    return True

G = [[] for i in range(N)]
for i in range(N - 1):
    for j in range(i + 1, N):
        if check(S[i], S[j]):
            G[i].append(j)
            G[j].append(i)
            
from collections import deque
q = deque([])
q.append([0, 0])
visited = [False] * N
visited[0] = True
while q:
    v, c = q.popleft()
    if v == N - 1:
        print(c - 1)
        break
    for child in G[v]:
        if visited[child]:
            continue
        visited[child] = True
        q.append([child, c + 1])
else:
    print(-1)
0