結果
問題 | No.2354 Poor Sight in Winter |
ユーザー |
![]() |
提出日時 | 2023-06-24 17:05:54 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 529 ms / 2,000 ms |
コード長 | 1,599 bytes |
コンパイル時間 | 174 ms |
コンパイル使用メモリ | 81,920 KB |
実行使用メモリ | 103,752 KB |
最終ジャッジ日時 | 2024-07-01 20:05:10 |
合計ジャッジ時間 | 7,225 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 |
ソースコード
# coding: utf-8# Your code here!from collections import defaultdictimport heapq as hqN,K=map(int,input().split())MAX=10**9edges=defaultdict(dict)def get_distance(loc1,loc2):x1,y1=loc1x2,y2=loc2return 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)]=distanceedges[(gx,gy)][(sx,sy)]=distancefor _ 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)]=distanceedges[(nx,ny)][(x,y)]=distancedef 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:continueelse:dp[now]=costif now==goal:breakfor (nx,ny),dist in edges[now].items():shortage=dist-pif p!=0:need_light=max(-(-shortage//p),0)else:need_light=shortageif cost+need_light<=K and dp[(nx,ny)]>cost+need_light:dp[(nx,ny)]=cost+need_lighthq.heappush(start,[cost+need_light,(nx,ny)])if dp[goal]<=K:return Trueelse:return Falsehigh=2*10**5+10low=0while high-low>1:middle=(high+low)//2judge=search_way(middle,(gx,gy))if judge:high=middleelse:low=middleprint(high)