結果

問題 No.1576 織姫と彦星
ユーザー m tm t
提出日時 2021-07-21 16:46:21
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 509 ms / 2,000 ms
コード長 492 bytes
コンパイル時間 97 ms
コンパイル使用メモリ 10,796 KB
実行使用メモリ 8,748 KB
最終ジャッジ日時 2023-09-24 13:14:15
合計ジャッジ時間 9,442 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,460 KB
testcase_01 AC 19 ms
8,528 KB
testcase_02 AC 19 ms
8,656 KB
testcase_03 AC 19 ms
8,700 KB
testcase_04 AC 19 ms
8,676 KB
testcase_05 AC 18 ms
8,648 KB
testcase_06 AC 19 ms
8,524 KB
testcase_07 AC 60 ms
8,692 KB
testcase_08 AC 33 ms
8,608 KB
testcase_09 AC 21 ms
8,524 KB
testcase_10 AC 243 ms
8,604 KB
testcase_11 AC 20 ms
8,620 KB
testcase_12 AC 144 ms
8,736 KB
testcase_13 AC 128 ms
8,604 KB
testcase_14 AC 233 ms
8,596 KB
testcase_15 AC 194 ms
8,616 KB
testcase_16 AC 101 ms
8,684 KB
testcase_17 AC 161 ms
8,716 KB
testcase_18 AC 46 ms
8,528 KB
testcase_19 AC 96 ms
8,684 KB
testcase_20 AC 23 ms
8,664 KB
testcase_21 AC 175 ms
8,668 KB
testcase_22 AC 48 ms
8,592 KB
testcase_23 AC 24 ms
8,636 KB
testcase_24 AC 37 ms
8,540 KB
testcase_25 AC 138 ms
8,704 KB
testcase_26 AC 120 ms
8,632 KB
testcase_27 AC 20 ms
8,548 KB
testcase_28 AC 137 ms
8,624 KB
testcase_29 AC 126 ms
8,604 KB
testcase_30 AC 20 ms
8,520 KB
testcase_31 AC 95 ms
8,712 KB
testcase_32 AC 154 ms
8,608 KB
testcase_33 AC 449 ms
8,628 KB
testcase_34 AC 20 ms
8,652 KB
testcase_35 AC 147 ms
8,700 KB
testcase_36 AC 40 ms
8,676 KB
testcase_37 AC 454 ms
8,600 KB
testcase_38 AC 192 ms
8,604 KB
testcase_39 AC 161 ms
8,624 KB
testcase_40 AC 110 ms
8,748 KB
testcase_41 AC 139 ms
8,704 KB
testcase_42 AC 26 ms
8,568 KB
testcase_43 AC 45 ms
8,588 KB
testcase_44 AC 509 ms
8,584 KB
testcase_45 AC 77 ms
8,508 KB
testcase_46 AC 320 ms
8,608 KB
testcase_47 AC 23 ms
8,736 KB
testcase_48 AC 174 ms
8,548 KB
testcase_49 AC 154 ms
8,668 KB
testcase_50 AC 23 ms
8,540 KB
testcase_51 AC 23 ms
8,584 KB
testcase_52 AC 40 ms
8,584 KB
testcase_53 AC 300 ms
8,588 KB
testcase_54 AC 166 ms
8,740 KB
testcase_55 AC 173 ms
8,604 KB
testcase_56 AC 182 ms
8,556 KB
testcase_57 AC 20 ms
8,580 KB
testcase_58 AC 62 ms
8,536 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,end]+stone

#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