結果

問題 No.2354 Poor Sight in Winter
ユーザー komkompikomkompi
提出日時 2023-06-24 17:05:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 552 ms / 2,000 ms
コード長 1,599 bytes
コンパイル時間 288 ms
コンパイル使用メモリ 87,160 KB
実行使用メモリ 106,728 KB
最終ジャッジ日時 2023-09-14 12:38:42
合計ジャッジ時間 9,061 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
71,460 KB
testcase_01 AC 93 ms
71,188 KB
testcase_02 AC 93 ms
71,576 KB
testcase_03 AC 93 ms
71,300 KB
testcase_04 AC 94 ms
71,508 KB
testcase_05 AC 93 ms
71,336 KB
testcase_06 AC 92 ms
71,672 KB
testcase_07 AC 92 ms
71,588 KB
testcase_08 AC 93 ms
71,588 KB
testcase_09 AC 113 ms
76,948 KB
testcase_10 AC 112 ms
77,204 KB
testcase_11 AC 272 ms
100,900 KB
testcase_12 AC 549 ms
106,728 KB
testcase_13 AC 412 ms
104,364 KB
testcase_14 AC 552 ms
104,676 KB
testcase_15 AC 374 ms
103,080 KB
testcase_16 AC 503 ms
104,272 KB
testcase_17 AC 510 ms
103,620 KB
testcase_18 AC 254 ms
86,528 KB
testcase_19 AC 406 ms
96,228 KB
testcase_20 AC 242 ms
86,800 KB
testcase_21 AC 187 ms
79,372 KB
testcase_22 AC 285 ms
83,532 KB
testcase_23 AC 217 ms
83,316 KB
testcase_24 AC 417 ms
94,132 KB
testcase_25 AC 231 ms
81,700 KB
testcase_26 AC 237 ms
81,000 KB
testcase_27 AC 134 ms
77,744 KB
testcase_28 AC 182 ms
78,632 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# coding: utf-8
# Your code here!
from collections import defaultdict
import heapq as hq

N,K=map(int,input().split())

MAX=10**9
edges=defaultdict(dict)

def get_distance(loc1,loc2):
    x1,y1=loc1
    x2,y2=loc2
    
    return abs(x2-x1)+abs(y2-y1)

sx,sy,gx,gy=map(int,input().split())
distance=get_distance((sx,sy),(gx,gy))
edges[(sx,sy)][(gx,gy)]=distance
edges[(gx,gy)][(sx,sy)]=distance

for _ in range(N):
    x,y=map(int,input().split())
    
    nodes=list(edges.keys())
    
    for nx,ny in nodes:
        distance=get_distance((x,y),(nx,ny))
        edges[(x,y)][(nx,ny)]=distance
        edges[(nx,ny)][(x,y)]=distance



def search_way(p,goal):
    dp=defaultdict(lambda:10**9)
    start=[[0,(sx,sy)]]
    hq.heapify(start)
    
    while start:
        cost,now=hq.heappop(start)
        if dp[now]<cost:
            continue
        else:
            dp[now]=cost
            if now==goal:
                break
        
        for (nx,ny),dist in edges[now].items():
            shortage=dist-p
            if p!=0:
                need_light=max(-(-shortage//p),0)
            else:
                need_light=shortage
            
            if cost+need_light<=K and dp[(nx,ny)]>cost+need_light:
                dp[(nx,ny)]=cost+need_light
                hq.heappush(start,[cost+need_light,(nx,ny)])

    if dp[goal]<=K:
        return True
    else:
        return False
            
high=2*10**5+10
low=0

while high-low>1:
    middle=(high+low)//2
    judge=search_way(middle,(gx,gy))
    
    if judge:
        high=middle
    else:
        low=middle
    
print(high)

0