結果

問題 No.2354 Poor Sight in Winter
ユーザー lloyz
提出日時 2023-06-17 20:25:16
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,235 bytes
コンパイル時間 478 ms
コンパイル使用メモリ 82,688 KB
実行使用メモリ 79,360 KB
最終ジャッジ日時 2024-06-25 10:17:59
合計ジャッジ時間 2,870 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 15 WA * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heapify, heappop, heappush
from collections import deque

n, k = map(int, input().split())
sx, sy, gx, gy = map(int, input().split())
P = [list(map(int, input().split())) for _ in range(n)]
P = [[sx, sy]] + P + [[gx, gy]]
D = [[0 for _ in range(n + 2)] for _ in range(n + 2)]
for i in range(n + 2):
    for j in range(n + 2):
        D[i][j] = abs(P[i][0] - P[j][0]) + abs(P[i][1] - P[j][1])

INF = 10**18
DD = [INF for _ in range(n + 2)]
DD[0] = 0
H = [(0, 0)]
while H:
    cd, cp = heappop(H)
    if cp == n + 1:
        break
    if cd > DD[cp]:
        continue
    for np in range(n + 2):
        if cd + D[cp][np] >= DD[np]:
            continue
        DD[np] = cd + D[cp][np]
        heappush(H, (DD[np], np))

R = []
cp = n + 1
while cp != 0:
    np = None
    res = INF
    for i in range(n + 2):
        if i == cp:
            continue
        if DD[i] + D[i][cp] == DD[cp]:
            if D[i][cp] < res:
                res = D[i][cp]
                np = i
    R.append(res)
    cp = np

m = len(R)
l, r = 0, INF
while r - l > 1:
    mid = (l + r) // 2
    cnt = 0
    for i in range(m):
        d = R[i]
        cnt += (d - 1) // mid
    if cnt > k:
        l = mid
    else:
        r = mid
print(r)
0