結果

問題 No.2354 Poor Sight in Winter
ユーザー FromBooskaFromBooska
提出日時 2023-06-18 17:55:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 498 ms / 2,000 ms
コード長 1,903 bytes
コンパイル時間 397 ms
コンパイル使用メモリ 87,128 KB
実行使用メモリ 88,860 KB
最終ジャッジ日時 2023-09-08 14:02:19
合計ジャッジ時間 9,135 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,216 KB
testcase_01 AC 77 ms
71,272 KB
testcase_02 AC 75 ms
71,400 KB
testcase_03 AC 76 ms
71,424 KB
testcase_04 AC 75 ms
71,176 KB
testcase_05 AC 76 ms
71,332 KB
testcase_06 AC 76 ms
71,208 KB
testcase_07 AC 75 ms
71,268 KB
testcase_08 AC 79 ms
71,372 KB
testcase_09 AC 89 ms
75,992 KB
testcase_10 AC 89 ms
76,456 KB
testcase_11 AC 388 ms
87,348 KB
testcase_12 AC 351 ms
86,588 KB
testcase_13 AC 494 ms
88,664 KB
testcase_14 AC 498 ms
88,860 KB
testcase_15 AC 460 ms
87,304 KB
testcase_16 AC 471 ms
87,836 KB
testcase_17 AC 475 ms
88,232 KB
testcase_18 AC 317 ms
83,892 KB
testcase_19 AC 418 ms
85,260 KB
testcase_20 AC 318 ms
82,432 KB
testcase_21 AC 174 ms
79,036 KB
testcase_22 AC 253 ms
80,796 KB
testcase_23 AC 262 ms
81,268 KB
testcase_24 AC 355 ms
84,648 KB
testcase_25 AC 213 ms
79,976 KB
testcase_26 AC 203 ms
79,716 KB
testcase_27 AC 125 ms
77,380 KB
testcase_28 AC 151 ms
78,472 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# BFS, ダイクストラのどちらかか、ワーシャルフロイドはないだろう
# ダイクストラでやってみるか
# Pによって各辺コストが変わる、(マンハッタン距離+2P-1)//2P
# それでK+1歩まででゴールにたどり着けるか
# を二分探索
# BFSだと盤面のマス目を距離で埋める必要あるが盤面がない
# 二分探索の都合上下限を0にできないと思ったけどできそう

N, K = map(int, input().split())
Sx, Sy, Gx, Gy = map(int, input().split())
XY = [(Sx, Sy, 0)]
for i in range(N):
    x, y = map(int, input().split())
    XY.append((x, y, i+1))
XY.append((Gx, Gy, N+1))

edges = [[] for i in range(N+2)]
for i in range(N+2):
    for j in range(i+1, N+2):
        cost = abs(XY[i][0]-XY[j][0])+abs(XY[i][1]-XY[j][1])
        edges[i].append((j, cost))
        edges[j].append((i, cost))
        
# ダイクストラの辺コストをPで改造したバージョン
from heapq import heappush, heappop
INF = 10 ** 18
def dijkstra(s, n, connect, P): #(始点, ノード数)
    distance = [INF] * n
    que = [(0, s)] #(distance, node)
    distance[s] = 0
    confirmed = [False] * n # ノードが確定済みかどうか
    while que:
        w,v = heappop(que)
        if distance[v]<w:
            continue
        confirmed[v] = True
        for to, cost in connect[v]: # ノード v に隣接しているノードに対して
            cost = (cost+P-1)//P-1
            if confirmed[to] == False and distance[v] + cost < distance[to]:
                distance[to] = distance[v] + cost
                heappush(que, (distance[to], to))
    return distance

#distance = dijkstra(0, N+2, edges, 4)
# 第2は頂点数、ゴールではない

NG = 0
OK = 10**8
while (OK-NG)>1:
    mid = (OK+NG)//2
    if dijkstra(0, N+2, edges, mid)[N+1] <= K:
        OK = mid
    else:
        NG = mid
print(OK)









0