結果

問題 No.2354 Poor Sight in Winter
ユーザー 👑 timitimi
提出日時 2023-06-16 22:46:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 561 ms / 2,000 ms
コード長 1,145 bytes
コンパイル時間 355 ms
コンパイル使用メモリ 86,888 KB
実行使用メモリ 83,796 KB
最終ジャッジ日時 2023-09-06 21:20:33
合計ジャッジ時間 8,152 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
71,328 KB
testcase_01 AC 67 ms
71,176 KB
testcase_02 AC 66 ms
71,472 KB
testcase_03 AC 67 ms
71,244 KB
testcase_04 AC 62 ms
71,332 KB
testcase_05 AC 66 ms
71,316 KB
testcase_06 AC 65 ms
71,284 KB
testcase_07 AC 65 ms
71,404 KB
testcase_08 AC 67 ms
71,188 KB
testcase_09 AC 73 ms
75,800 KB
testcase_10 AC 73 ms
75,796 KB
testcase_11 AC 336 ms
81,016 KB
testcase_12 AC 301 ms
80,240 KB
testcase_13 AC 537 ms
82,516 KB
testcase_14 AC 561 ms
83,796 KB
testcase_15 AC 452 ms
81,516 KB
testcase_16 AC 461 ms
82,324 KB
testcase_17 AC 541 ms
83,360 KB
testcase_18 AC 271 ms
79,828 KB
testcase_19 AC 442 ms
82,992 KB
testcase_20 AC 311 ms
81,028 KB
testcase_21 AC 149 ms
78,836 KB
testcase_22 AC 207 ms
79,300 KB
testcase_23 AC 237 ms
80,044 KB
testcase_24 AC 360 ms
81,412 KB
testcase_25 AC 195 ms
78,764 KB
testcase_26 AC 190 ms
79,248 KB
testcase_27 AC 117 ms
77,464 KB
testcase_28 AC 142 ms
78,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

M,K=map(int, input().split())
sx,sy,gx,gy=map(int, input().split())
A=[]
A.append((sx,sy))
for i in range(M):
  x,y=map(int, input().split())
  A.append((x,y))
A.append((gx,gy))
D=[[10**10]*len(A) for i in range(len(A))]
for i in range(len(A)):
  for j in range(len(A)):
    d=abs(A[i][0]-A[j][0])+abs(A[i][1]-A[j][1])
    D[i][j]=d 
    
N=M+2
import heapq
def dijkstra(s,p):
    hq=[(0,s,0)]
    ans=[]
    heapq.heapify(hq) # リストを優先度付きキューに変換
    cost=[10**6]*N # 行ったことのないところはinf
    cost[s]=0 # 開始地点は0
    while hq:
      c,v,pre=heapq.heappop(hq)
      if c>cost[v]: # コストが現在のコストよりも高ければスルー v:now u:nex
        continue
      for u in range(N):
        if pre==u:
          continue
        if D[u][v]%p==0:
          d=D[u][v]//p-1 
        else:
          d=D[u][v]//p
        d=max(d,0)
        tmp=d+cost[v]
        if tmp<cost[u]:
          cost[u]=tmp
          heapq.heappush(hq,(tmp,u,v))
    return cost

ng,ok=0,2*10**5
while ok-ng>1:
  mid=(ok+ng)//2
  c=dijkstra(0,mid)[-1]
  if c>K:
    ng=mid 
  else:
    ok=mid
print(ok)
0