結果

問題 No.1576 織姫と彦星
ユーザー m tm t
提出日時 2021-07-21 13:24:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 938 ms / 2,000 ms
コード長 538 bytes
コンパイル時間 630 ms
コンパイル使用メモリ 86,992 KB
実行使用メモリ 78,248 KB
最終ジャッジ日時 2023-09-24 13:06:50
合計ジャッジ時間 19,119 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
71,676 KB
testcase_01 AC 95 ms
71,620 KB
testcase_02 AC 94 ms
71,520 KB
testcase_03 AC 94 ms
71,628 KB
testcase_04 AC 95 ms
71,648 KB
testcase_05 AC 94 ms
71,680 KB
testcase_06 AC 95 ms
71,420 KB
testcase_07 AC 185 ms
77,736 KB
testcase_08 AC 133 ms
77,524 KB
testcase_09 AC 110 ms
77,576 KB
testcase_10 AC 483 ms
78,052 KB
testcase_11 AC 108 ms
77,672 KB
testcase_12 AC 314 ms
78,060 KB
testcase_13 AC 301 ms
77,848 KB
testcase_14 AC 461 ms
77,956 KB
testcase_15 AC 406 ms
78,080 KB
testcase_16 AC 239 ms
77,836 KB
testcase_17 AC 345 ms
78,096 KB
testcase_18 AC 155 ms
77,548 KB
testcase_19 AC 244 ms
78,128 KB
testcase_20 AC 113 ms
77,416 KB
testcase_21 AC 379 ms
78,184 KB
testcase_22 AC 157 ms
77,944 KB
testcase_23 AC 118 ms
77,928 KB
testcase_24 AC 142 ms
77,696 KB
testcase_25 AC 317 ms
78,040 KB
testcase_26 AC 287 ms
78,248 KB
testcase_27 AC 112 ms
77,596 KB
testcase_28 AC 307 ms
77,980 KB
testcase_29 AC 301 ms
77,996 KB
testcase_30 AC 103 ms
76,560 KB
testcase_31 AC 248 ms
78,144 KB
testcase_32 AC 339 ms
77,956 KB
testcase_33 AC 821 ms
78,080 KB
testcase_34 AC 112 ms
77,836 KB
testcase_35 AC 316 ms
77,896 KB
testcase_36 AC 146 ms
77,868 KB
testcase_37 AC 860 ms
78,124 KB
testcase_38 AC 393 ms
77,968 KB
testcase_39 AC 346 ms
78,032 KB
testcase_40 AC 261 ms
78,080 KB
testcase_41 AC 309 ms
78,144 KB
testcase_42 AC 119 ms
77,524 KB
testcase_43 AC 155 ms
77,776 KB
testcase_44 AC 938 ms
78,124 KB
testcase_45 AC 206 ms
77,776 KB
testcase_46 AC 603 ms
77,980 KB
testcase_47 AC 115 ms
77,416 KB
testcase_48 AC 374 ms
77,960 KB
testcase_49 AC 343 ms
78,180 KB
testcase_50 AC 113 ms
77,732 KB
testcase_51 AC 115 ms
77,776 KB
testcase_52 AC 146 ms
77,800 KB
testcase_53 AC 580 ms
77,948 KB
testcase_54 AC 355 ms
78,156 KB
testcase_55 AC 363 ms
77,732 KB
testcase_56 AC 384 ms
77,948 KB
testcase_57 AC 108 ms
77,852 KB
testcase_58 AC 181 ms
77,976 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
#ハミング距離
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]

#BFS
dist=[False]*(n+2)
que=deque([0])
dist[0]=0
while que:
    v=que.popleft()
    for u in range(n+2):
        if hamming(x[v],x[u])==1 and dist[u]==False:
            dist[u]=dist[v]+1
            que.append(u)

res=dist[-1]
if not res:
    print(-1)
else:
    print(res-1)         
0