結果

問題 No.2695 Warp Zone
ユーザー ゼット
提出日時 2024-03-22 21:56:50
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 789 bytes
コンパイル時間 377 ms
コンパイル使用メモリ 82,548 KB
実行使用メモリ 139,492 KB
最終ジャッジ日時 2024-09-30 11:27:53
合計ジャッジ時間 4,042 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 3
other AC * 2 WA * 1 TLE * 1 -- * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

H,W,N=map(int,input().split())
result=H-1+W-1
from heapq import heappush,heappop
L=[]
for i in range(N):
  x,y,c,d=map(int,input().split())
  L.append((x,y,c,d))
for s in range(N):
  dist=[10**15]*N
  kaku=[0]*N
  S=[]
  x,y=L[s][0],L[s][1]
  dist[s]=abs(x-1)+abs(y-1)
  heappush(S,dist[s]*10**10+s)
  while S:
    w=heappop(S)
    time=w//(10**10)
    pos=w%(10**10)
    if kaku[pos]==True:
      continue
    kaku[pos]=True
    c,d=L[pos][2],L[pos][3]
    for j in range(N):
      if kaku[j]==True:
        continue
      x,y=L[j][0],L[j][1]
      di=abs(x-c)+abs(y-d)
      if dist[j]>dist[pos]+di+1:
        dist[j]=dist[pos]+di
        heappush(S,dist[j]*10**10+j)
  for i in range(N):
    c,d=L[i][2],L[i][3]
    di=abs(c-H)+abs(d-W)
    result=min(result,dist[i]+di+1)
print(result)
0