結果
| 問題 |
No.1577 織姫と彦星2
|
| ユーザー |
|
| 提出日時 | 2021-07-21 13:25:27 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 538 bytes |
| コンパイル時間 | 162 ms |
| コンパイル使用メモリ | 82,180 KB |
| 実行使用メモリ | 88,856 KB |
| 最終ジャッジ日時 | 2024-07-17 13:59:44 |
| 合計ジャッジ時間 | 4,479 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 2 TLE * 1 -- * 50 |
ソースコード
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)