結果

問題 No.2354 Poor Sight in Winter
ユーザー minimum
提出日時 2023-06-16 22:38:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,914 ms / 2,000 ms
コード長 816 bytes
コンパイル時間 356 ms
コンパイル使用メモリ 82,472 KB
実行使用メモリ 78,080 KB
最終ジャッジ日時 2024-06-24 15:22:02
合計ジャッジ時間 13,114 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappop, heappush


INF = 10 ** 18
C = 10 ** 7
N, K = map(int, input().split())
sx, sy, gx, gy = map(int, input().split())
X, Y = [sx, gx], [sy, gy]
for _ in range(N):
    x, y = map(int, input().split())
    X.append(x)
    Y.append(y)

def solve(P):
    hq = []
    heappush(hq, 0)
    dist = [INF] * (N + 2)
    dist[0] = 0
    while hq:
        now = heappop(hq) % C
        for i in range(N + 2):
            if now == i:
                continue
            ndist = dist[now] + (abs(X[i] - X[now]) + abs(Y[i] - Y[now]) - 1) // P
            if dist[i] > ndist:
                dist[i] = ndist
                heappush(hq, ndist * C + i)
    return dist[1] <= K


lo = 0
hi = 10 ** 6
while hi - lo > 1:
    p = (hi + lo) // 2
    if solve(p):
        hi = p
    else:
        lo = p

print(hi)
0