結果

問題 No.1576 織姫と彦星
ユーザー m tm t
提出日時 2021-07-21 13:47:27
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 504 ms / 2,000 ms
コード長 495 bytes
コンパイル時間 85 ms
コンパイル使用メモリ 10,904 KB
実行使用メモリ 8,700 KB
最終ジャッジ日時 2023-09-24 13:07:25
合計ジャッジ時間 8,672 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,496 KB
testcase_01 AC 17 ms
8,476 KB
testcase_02 AC 17 ms
8,440 KB
testcase_03 AC 17 ms
8,540 KB
testcase_04 AC 17 ms
8,548 KB
testcase_05 AC 17 ms
8,580 KB
testcase_06 AC 17 ms
8,500 KB
testcase_07 AC 58 ms
8,624 KB
testcase_08 AC 31 ms
8,572 KB
testcase_09 AC 19 ms
8,504 KB
testcase_10 AC 226 ms
8,620 KB
testcase_11 AC 19 ms
8,580 KB
testcase_12 AC 132 ms
8,580 KB
testcase_13 AC 124 ms
8,544 KB
testcase_14 AC 222 ms
8,664 KB
testcase_15 AC 178 ms
8,668 KB
testcase_16 AC 95 ms
8,632 KB
testcase_17 AC 153 ms
8,608 KB
testcase_18 AC 44 ms
8,600 KB
testcase_19 AC 90 ms
8,568 KB
testcase_20 AC 22 ms
8,556 KB
testcase_21 AC 169 ms
8,660 KB
testcase_22 AC 45 ms
8,688 KB
testcase_23 AC 22 ms
8,524 KB
testcase_24 AC 35 ms
8,604 KB
testcase_25 AC 138 ms
8,580 KB
testcase_26 AC 118 ms
8,648 KB
testcase_27 AC 19 ms
8,508 KB
testcase_28 AC 137 ms
8,656 KB
testcase_29 AC 119 ms
8,528 KB
testcase_30 AC 18 ms
8,480 KB
testcase_31 AC 93 ms
8,504 KB
testcase_32 AC 146 ms
8,568 KB
testcase_33 AC 425 ms
8,700 KB
testcase_34 AC 19 ms
8,456 KB
testcase_35 AC 142 ms
8,528 KB
testcase_36 AC 37 ms
8,496 KB
testcase_37 AC 443 ms
8,620 KB
testcase_38 AC 193 ms
8,668 KB
testcase_39 AC 150 ms
8,608 KB
testcase_40 AC 107 ms
8,508 KB
testcase_41 AC 132 ms
8,576 KB
testcase_42 AC 24 ms
8,508 KB
testcase_43 AC 42 ms
8,644 KB
testcase_44 AC 504 ms
8,688 KB
testcase_45 AC 74 ms
8,656 KB
testcase_46 AC 310 ms
8,588 KB
testcase_47 AC 22 ms
8,508 KB
testcase_48 AC 166 ms
8,600 KB
testcase_49 AC 145 ms
8,604 KB
testcase_50 AC 21 ms
8,584 KB
testcase_51 AC 21 ms
8,552 KB
testcase_52 AC 38 ms
8,596 KB
testcase_53 AC 297 ms
8,524 KB
testcase_54 AC 154 ms
8,668 KB
testcase_55 AC 167 ms
8,544 KB
testcase_56 AC 174 ms
8,628 KB
testcase_57 AC 19 ms
8,548 KB
testcase_58 AC 59 ms
8,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
#ハミング距離
def hamming(a,b):
    return bin(a^b).count('1')

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