結果
| 問題 | No.1576 織姫と彦星 |
| ユーザー |
|
| 提出日時 | 2021-07-21 16:48:50 |
| 言語 | Python3 (3.14.3 + numpy 2.4.4 + scipy 1.17.1) |
| 結果 |
AC
|
| 実行時間 | 354 ms / 2,000 ms |
| コード長 | 491 bytes |
| 記録 | |
| コンパイル時間 | 567 ms |
| コンパイル使用メモリ | 20,824 KB |
| 実行使用メモリ | 15,364 KB |
| 最終ジャッジ日時 | 2026-04-01 05:06:24 |
| 合計ジャッジ時間 | 11,584 ms |
|
ジャッジサーバーID (参考情報) |
judge2_1 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 54 |
ソースコード
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)