結果
| 問題 |
No.1576 織姫と彦星
|
| ユーザー |
|
| 提出日時 | 2021-07-21 13:04:10 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 731 bytes |
| コンパイル時間 | 274 ms |
| コンパイル使用メモリ | 12,928 KB |
| 実行使用メモリ | 17,952 KB |
| 最終ジャッジ日時 | 2024-07-17 13:58:28 |
| 合計ジャッジ時間 | 35,530 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 28 TLE * 5 -- * 21 |
ソースコード
from collections import deque
def BFS(s,N):
dist=[False]*N
que=deque([0])
dist[0]=0
while que:
v=que.popleft()
for u in graph[v]:
if not dist[u]:
dist[u]=dist[v]+1
que.append(u)
return dist[-1]
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]
graph=[[] for i in range(n+2)]
for i in range(n+1):
for j in range(i+1,n+2):
if hamming(x[i],x[j])==1:
graph[i].append(j)
graph[j].append(i)
res=BFS(0,n+2)
if not res:
print(-1)
else:
print(res-1)