結果
| 問題 |
No.2354 Poor Sight in Winter
|
| コンテスト | |
| ユーザー |
timi
|
| 提出日時 | 2023-06-16 22:46:15 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 631 ms / 2,000 ms |
| コード長 | 1,145 bytes |
| コンパイル時間 | 309 ms |
| コンパイル使用メモリ | 82,304 KB |
| 実行使用メモリ | 82,944 KB |
| 最終ジャッジ日時 | 2024-06-24 15:40:18 |
| 合計ジャッジ時間 | 7,723 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 26 |
ソースコード
M,K=map(int, input().split())
sx,sy,gx,gy=map(int, input().split())
A=[]
A.append((sx,sy))
for i in range(M):
x,y=map(int, input().split())
A.append((x,y))
A.append((gx,gy))
D=[[10**10]*len(A) for i in range(len(A))]
for i in range(len(A)):
for j in range(len(A)):
d=abs(A[i][0]-A[j][0])+abs(A[i][1]-A[j][1])
D[i][j]=d
N=M+2
import heapq
def dijkstra(s,p):
hq=[(0,s,0)]
ans=[]
heapq.heapify(hq) # リストを優先度付きキューに変換
cost=[10**6]*N # 行ったことのないところはinf
cost[s]=0 # 開始地点は0
while hq:
c,v,pre=heapq.heappop(hq)
if c>cost[v]: # コストが現在のコストよりも高ければスルー v:now u:nex
continue
for u in range(N):
if pre==u:
continue
if D[u][v]%p==0:
d=D[u][v]//p-1
else:
d=D[u][v]//p
d=max(d,0)
tmp=d+cost[v]
if tmp<cost[u]:
cost[u]=tmp
heapq.heappush(hq,(tmp,u,v))
return cost
ng,ok=0,2*10**5
while ok-ng>1:
mid=(ok+ng)//2
c=dijkstra(0,mid)[-1]
if c>K:
ng=mid
else:
ok=mid
print(ok)
timi