結果

問題 No.2354 Poor Sight in Winter
ユーザー yabityabit
提出日時 2023-07-05 17:04:30
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,255 ms / 2,000 ms
コード長 1,183 bytes
コンパイル時間 311 ms
コンパイル使用メモリ 86,696 KB
実行使用メモリ 230,308 KB
最終ジャッジ日時 2023-09-26 17:20:29
合計ジャッジ時間 11,731 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
71,252 KB
testcase_01 AC 82 ms
71,072 KB
testcase_02 AC 79 ms
71,140 KB
testcase_03 AC 80 ms
71,216 KB
testcase_04 AC 79 ms
71,124 KB
testcase_05 AC 79 ms
71,172 KB
testcase_06 AC 78 ms
71,128 KB
testcase_07 AC 79 ms
71,140 KB
testcase_08 AC 79 ms
71,256 KB
testcase_09 AC 88 ms
76,152 KB
testcase_10 AC 91 ms
75,928 KB
testcase_11 AC 543 ms
212,988 KB
testcase_12 AC 548 ms
207,076 KB
testcase_13 AC 849 ms
229,004 KB
testcase_14 AC 1,255 ms
230,308 KB
testcase_15 AC 815 ms
223,416 KB
testcase_16 AC 1,046 ms
224,144 KB
testcase_17 AC 767 ms
229,000 KB
testcase_18 AC 356 ms
103,292 KB
testcase_19 AC 563 ms
161,216 KB
testcase_20 AC 420 ms
110,256 KB
testcase_21 AC 172 ms
78,776 KB
testcase_22 AC 259 ms
87,232 KB
testcase_23 AC 312 ms
87,208 KB
testcase_24 AC 483 ms
139,784 KB
testcase_25 AC 203 ms
82,508 KB
testcase_26 AC 189 ms
79,928 KB
testcase_27 AC 123 ms
77,848 KB
testcase_28 AC 144 ms
78,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq

N, K = map(int, input().split())
sx, sy, gx, gy = map(int, input().split())
X = [sx, gx]
Y = [sy, gy]
for i in range(N):
    x, y = map(int, input().split())
    X.append(x)
    Y.append(y)

D = [[0] * (N + 2) for _ in range(N + 2)]
for i in range(N + 2):
    for j in range(i + 1, N + 2):
        D[i][j] = abs(X[i] - X[j]) + abs(Y[i] - Y[j])
        D[j][i] = abs(X[i] - X[j]) + abs(Y[i] - Y[j])


def dijkstra(start, G):
    INF = 10**9
    dist = [INF] * len(G)
    hq = [(0, start)]
    heapq.heapify(hq)
    dist[start] = 0
    while hq:
        v = heapq.heappop(hq)[1]
        for u, cost in G[v]:
            if dist[v] + cost < dist[u]:
                dist[u] = dist[v] + cost
                heapq.heappush(hq, (dist[u], u))
    return dist


def solve(P):
    G = [[] for _ in range(N + 2)]
    for i in range(N + 2):
        for j in range(i + 1, N + 2):
            di = -(-D[i][j] // P) - 1
            G[i].append((j, di))
            G[j].append((i, di))
    dist = dijkstra(0, G)
    return dist[1] <= K


ng, ok = 0, 2 * 10**5 + 10
while ok - ng > 1:
    mid = (ng + ok) // 2
    if solve(mid):
        ok = mid
    else:
        ng = mid
print(ok)
0