結果

問題 No.2354 Poor Sight in Winter
ユーザー komkompikomkompi
提出日時 2023-06-24 16:26:18
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,469 bytes
コンパイル時間 269 ms
コンパイル使用メモリ 86,780 KB
実行使用メモリ 156,012 KB
最終ジャッジ日時 2023-09-14 11:56:50
合計ジャッジ時間 6,165 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
71,704 KB
testcase_01 AC 92 ms
71,500 KB
testcase_02 AC 92 ms
71,564 KB
testcase_03 AC 92 ms
71,432 KB
testcase_04 AC 90 ms
71,468 KB
testcase_05 AC 89 ms
71,392 KB
testcase_06 AC 90 ms
71,564 KB
testcase_07 AC 89 ms
71,296 KB
testcase_08 AC 88 ms
71,160 KB
testcase_09 AC 144 ms
77,992 KB
testcase_10 AC 136 ms
78,100 KB
testcase_11 AC 762 ms
154,016 KB
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

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
            
            hq.heappush(start,[cost+need_light,(nx,ny)])

    if dp[goal]<=K:
        return True
    else:
        return False
            
high=10**9
low=-1

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