結果

問題 No.1576 織姫と彦星
ユーザー m tm t
提出日時 2021-07-21 13:04:10
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 731 bytes
コンパイル時間 288 ms
コンパイル使用メモリ 10,872 KB
実行使用メモリ 8,896 KB
最終ジャッジ日時 2023-09-24 13:05:31
合計ジャッジ時間 50,917 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,532 KB
testcase_01 AC 18 ms
8,600 KB
testcase_02 AC 17 ms
8,596 KB
testcase_03 AC 17 ms
8,580 KB
testcase_04 AC 17 ms
8,656 KB
testcase_05 AC 18 ms
8,548 KB
testcase_06 AC 21 ms
8,572 KB
testcase_07 AC 552 ms
8,716 KB
testcase_08 AC 402 ms
8,628 KB
testcase_09 AC 26 ms
8,552 KB
testcase_10 AC 1,608 ms
8,832 KB
testcase_11 AC 30 ms
8,540 KB
testcase_12 AC 966 ms
8,648 KB
testcase_13 TLE -
testcase_14 AC 1,266 ms
8,720 KB
testcase_15 AC 1,255 ms
8,796 KB
testcase_16 AC 1,696 ms
8,696 KB
testcase_17 AC 1,269 ms
8,752 KB
testcase_18 AC 196 ms
8,608 KB
testcase_19 AC 369 ms
8,640 KB
testcase_20 AC 1,351 ms
8,792 KB
testcase_21 AC 1,148 ms
8,788 KB
testcase_22 AC 1,499 ms
8,640 KB
testcase_23 AC 156 ms
8,680 KB
testcase_24 AC 148 ms
8,556 KB
testcase_25 AC 1,803 ms
8,748 KB
testcase_26 AC 479 ms
8,620 KB
testcase_27 AC 42 ms
8,540 KB
testcase_28 AC 1,544 ms
8,748 KB
testcase_29 AC 482 ms
8,656 KB
testcase_30 AC 20 ms
8,672 KB
testcase_31 AC 549 ms
8,728 KB
testcase_32 AC 1,219 ms
8,668 KB
testcase_33 TLE -
testcase_34 AC 31 ms
8,612 KB
testcase_35 AC 679 ms
8,664 KB
testcase_36 AC 122 ms
8,568 KB
testcase_37 TLE -
testcase_38 AC 1,534 ms
8,788 KB
testcase_39 AC 812 ms
8,696 KB
testcase_40 AC 583 ms
8,644 KB
testcase_41 AC 756 ms
8,660 KB
testcase_42 AC 50 ms
8,548 KB
testcase_43 AC 199 ms
8,728 KB
testcase_44 TLE -
testcase_45 AC 561 ms
8,712 KB
testcase_46 AC 1,392 ms
8,696 KB
testcase_47 AC 242 ms
8,608 KB
testcase_48 AC 795 ms
8,628 KB
testcase_49 AC 730 ms
8,728 KB
testcase_50 AC 37 ms
8,544 KB
testcase_51 AC 148 ms
8,604 KB
testcase_52 TLE -
testcase_53 AC 1,242 ms
8,728 KB
testcase_54 AC 1,721 ms
8,656 KB
testcase_55 TLE -
testcase_56 TLE -
testcase_57 AC 26 ms
8,556 KB
testcase_58 AC 447 ms
8,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
def BFS(s,N):
    dist=[False]*N
    que=deque([0])
    dist[0]=0
    while que:
        v=que.popleft()
        for u in graph[v]:
            if not dist[u]:
                dist[u]=dist[v]+1
                que.append(u)
    return dist[-1]

def hamming(a,b):
    x=bin(a^b)
    d=0
    for i in x[2:]:
        d+=int(i)
    return d

n=int(input())
start,end=map(int,input().split())
stone=list(map(int,input().split()))

x=[start]+stone+[end]
graph=[[] for i in range(n+2)]
for i in range(n+1):
    for j in range(i+1,n+2):
        if hamming(x[i],x[j])==1:
            graph[i].append(j)
            graph[j].append(i)
            
res=BFS(0,n+2)
if not res:
    print(-1)
else:
    print(res-1)
0