結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,484 KB
testcase_01 AC 18 ms
8,536 KB
testcase_02 AC 18 ms
8,616 KB
testcase_03 AC 18 ms
8,524 KB
testcase_04 AC 17 ms
8,456 KB
testcase_05 AC 17 ms
8,492 KB
testcase_06 AC 17 ms
8,512 KB
testcase_07 AC 59 ms
8,640 KB
testcase_08 AC 30 ms
8,536 KB
testcase_09 AC 19 ms
8,480 KB
testcase_10 AC 225 ms
8,616 KB
testcase_11 AC 18 ms
8,552 KB
testcase_12 AC 138 ms
8,564 KB
testcase_13 AC 121 ms
8,588 KB
testcase_14 AC 227 ms
8,576 KB
testcase_15 AC 189 ms
8,564 KB
testcase_16 AC 91 ms
8,612 KB
testcase_17 AC 155 ms
8,520 KB
testcase_18 AC 43 ms
8,556 KB
testcase_19 AC 92 ms
8,632 KB
testcase_20 AC 21 ms
8,672 KB
testcase_21 AC 167 ms
8,680 KB
testcase_22 AC 44 ms
8,676 KB
testcase_23 AC 22 ms
8,520 KB
testcase_24 AC 36 ms
8,620 KB
testcase_25 AC 137 ms
8,700 KB
testcase_26 AC 114 ms
8,640 KB
testcase_27 AC 19 ms
8,464 KB
testcase_28 AC 137 ms
8,624 KB
testcase_29 AC 121 ms
8,640 KB
testcase_30 AC 18 ms
8,652 KB
testcase_31 AC 92 ms
8,512 KB
testcase_32 AC 144 ms
8,712 KB
testcase_33 AC 435 ms
8,712 KB
testcase_34 AC 19 ms
8,504 KB
testcase_35 AC 141 ms
8,580 KB
testcase_36 AC 38 ms
8,484 KB
testcase_37 AC 469 ms
8,696 KB
testcase_38 AC 181 ms
8,608 KB
testcase_39 AC 153 ms
8,516 KB
testcase_40 AC 109 ms
8,636 KB
testcase_41 AC 134 ms
8,660 KB
testcase_42 AC 25 ms
8,608 KB
testcase_43 AC 46 ms
8,572 KB
testcase_44 AC 489 ms
8,644 KB
testcase_45 AC 74 ms
8,540 KB
testcase_46 AC 314 ms
8,700 KB
testcase_47 AC 21 ms
8,644 KB
testcase_48 AC 166 ms
8,552 KB
testcase_49 AC 150 ms
8,552 KB
testcase_50 AC 21 ms
8,504 KB
testcase_51 AC 22 ms
8,612 KB
testcase_52 AC 39 ms
8,628 KB
testcase_53 AC 282 ms
8,596 KB
testcase_54 AC 165 ms
8,632 KB
testcase_55 AC 166 ms
8,628 KB
testcase_56 AC 181 ms
8,704 KB
testcase_57 AC 19 ms
8,532 KB
testcase_58 AC 61 ms
8,684 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=[start,end]+list(map(int,input().split()))
#BFS
dist=[False]*(n+2)
que=deque([0])
dist[0]=0
while que:
    v=que.popleft()
    for u in range(n+2):
        if hamming(stone[v],stone[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