結果

問題 No.2354 Poor Sight in Winter
ユーザー AngrySadEight
提出日時 2023-04-04 09:40:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 505 ms / 2,000 ms
コード長 1,462 bytes
コンパイル時間 365 ms
コンパイル使用メモリ 82,028 KB
実行使用メモリ 101,576 KB
最終ジャッジ日時 2024-09-25 11:04:58
合計ジャッジ時間 6,540 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq

def dijkstra(graph, v, dist, P):
    hq = []
    heapq.heappush(hq, [0, v])
    dist[v] = 0
    while len(hq) > 0:
        min_d, cur = heapq.heappop(hq)
        if dist[cur] != min_d:
            continue
        for next_cur, next_d in graph[cur]:
            if dist[next_cur] > dist[cur] + (next_d + P - 1) // P - 1:
                dist[next_cur] = dist[cur] + (next_d + P - 1) // P - 1
                heapq.heappush(hq, [dist[next_cur], next_cur])


N, K = map(int, input().split())
sx, sy, gx, gy = map(int, input().split())
graph = [[] for _ in range(N + 2)]
X = []
Y = []
for i in range(N):
    x, y = map(int, input().split())
    X.append(x)
    Y.append(y)
for i in range(N):
    for j in range(N):
        if i != j:
            graph[i].append([j, abs(X[i] - X[j]) + abs(Y[i] - Y[j])])
for i in range(N):
    graph[N].append([i, abs(X[i] - sx) + abs(Y[i] - sy)])
    graph[i].append([N, abs(X[i] - sx) + abs(Y[i] - sy)])
for i in range(N):
    graph[N + 1].append([i, abs(X[i] - gx) + abs(Y[i] - gy)])
    graph[i].append([N + 1, abs(X[i] - gx) + abs(Y[i] - gy)])
graph[N].append([N + 1, abs(sx - gx) + abs(sy - gy)])
graph[N + 1].append([N, abs(sx - gx) + abs(sy - gy)])

INF = 10 ** 7

ng = 0
ok = 200002
while ok - ng > 1:
    center = (ok + ng) // 2
    dist = [INF for _ in range(N + 2)]
    dijkstra(graph, N, dist, center)
    if dist[N + 1] <= K:
        ok = center
    else:
        ng = center
    #print(ok, ng)
print(ok)
0