結果

問題 No.2354 Poor Sight in Winter
ユーザー Navier_Boltzmann
提出日時 2023-06-17 01:03:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 478 ms / 2,000 ms
コード長 1,092 bytes
コンパイル時間 192 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 88,320 KB
最終ジャッジ日時 2024-06-24 17:55:46
合計ジャッジ時間 7,301 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import *
from itertools import *
from functools import *
from heapq import *
import sys,math
input = sys.stdin.readline

N,K = map(int,input().split())
sx,sy,gx,gy = map(int,input().split())
xy = [tuple(map(int,input().split())) for _ in range(N)]
xy = [(sx,sy)] + xy + [(gx,gy)]
e = [[] for _ in range(N+2)]
for i in range(N+1):
    xi,yi = xy[i]
    for j in range(i+1,N+2):
        xj,yj = xy[j]
        d = abs(xi-xj)+abs(yi-yj)
        e[i].append((j,d))
        e[j].append((i,d))
INF = (1<<30)
def dijkstra(s,e,k):
    
    N = len(e)
    dist = [INF]*N
    dist[s]=0
    h = []
    heappush(h,(0,s))
    while h:
        nw,v = heappop(h)
        if dist[v]!=nw:
            continue
        for iv,ic in e[v]:
            nc = (ic-1)//k + nw
            if nc < dist[iv]:
                dist[iv] = nc
                heappush(h,(nc,iv))
    return dist
    
    
def is_ok(k):
    
    return dijkstra(0,e,k)[N+1]<=K
if is_ok(1):
	print(1)
	exit()
x = 1
y = 10**7
while y-x>1:
    mid = (y+x)//2
    if is_ok(mid):
        y = mid
    else:
        x = mid
print(y)
0