結果

問題 No.2695 Warp Zone
ユーザー ゼットゼット
提出日時 2024-03-22 22:00:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 180 ms / 2,000 ms
コード長 785 bytes
コンパイル時間 314 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 77,320 KB
最終ジャッジ日時 2024-03-22 22:00:41
合計ジャッジ時間 3,933 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
53,460 KB
testcase_01 AC 41 ms
53,460 KB
testcase_02 AC 38 ms
53,460 KB
testcase_03 AC 172 ms
77,036 KB
testcase_04 AC 150 ms
76,912 KB
testcase_05 AC 151 ms
76,920 KB
testcase_06 AC 147 ms
76,772 KB
testcase_07 AC 150 ms
76,780 KB
testcase_08 AC 49 ms
61,840 KB
testcase_09 AC 180 ms
76,316 KB
testcase_10 AC 39 ms
53,460 KB
testcase_11 AC 91 ms
76,220 KB
testcase_12 AC 124 ms
76,164 KB
testcase_13 AC 39 ms
53,460 KB
testcase_14 AC 157 ms
77,320 KB
testcase_15 AC 116 ms
76,316 KB
testcase_16 AC 94 ms
76,096 KB
testcase_17 AC 109 ms
76,200 KB
testcase_18 AC 142 ms
76,936 KB
testcase_19 AC 47 ms
61,848 KB
testcase_20 AC 135 ms
76,812 KB
testcase_21 AC 158 ms
76,808 KB
testcase_22 AC 118 ms
76,328 KB
testcase_23 AC 141 ms
77,200 KB
testcase_24 AC 39 ms
53,460 KB
testcase_25 AC 39 ms
53,460 KB
testcase_26 AC 39 ms
53,460 KB
権限があれば一括ダウンロードができます

ソースコード

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))
kaku=[False]*N
dist=[10**15]*N
S=[]
for i in range(N):
  x,y=L[i][0],L[i][1]
  dist[i]=abs(x-1)+abs(y-1)
  heappush(S,dist[i]*10**10+i)
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+1
        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