結果

問題 No.2695 Warp Zone
ユーザー mutualnsmutualns
提出日時 2024-03-23 06:25:26
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,040 bytes
コンパイル時間 286 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 429,956 KB
最終ジャッジ日時 2024-03-23 06:25:53
合計ジャッジ時間 26,233 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,460 KB
testcase_01 WA -
testcase_02 AC 40 ms
53,460 KB
testcase_03 TLE -
testcase_04 TLE -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 39 ms
53,460 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 39 ms
53,460 KB
testcase_26 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq

h,w,n=map(int,input().split())

wps=[]
wpt=[]
for i in range(n):
  a,b,c,d=map(int,input().split())
  wps.append([a,b])
  wpt.append([c,d])

def dist(x,y):
  return (abs(x[0]-y[0])+abs(x[1]-y[1]))

d=[10**18]*(2+n*2)
d[0]=0

g=[[] for _ in range(2+n*2)]
for i in range(n):
  g[0].append([2*i+2,dist([1,1],wps[i])])
  g[0].append([2*i+3,dist([1,1],wpt[i])])
g[0].append([1,dist([1,1],[h,w])])

for i in range(n):
  g[2*i+2].append([2*i+3,1])
  g[2*i+3].append([2*i+2,dist(wps[i],wpt[i])])
  g[2*i+2].append([1,dist(wps[i],[h,w])])
  g[2*i+3].append([1,dist(wpt[i],[h,w])])
  for j in range(n):
    if i==j:
      continue
    g[2*i+2].append([2*j+2,dist(wps[i],wps[j])])
    g[2*i+2].append([2*j+3,dist(wps[i],wpt[j])])
    g[2*i+3].append([2*j+2,dist(wpt[i],wps[j])])
    g[2*i+3].append([2*j+3,dist(wpt[i],wpt[j])])
    
hq=[(0,0)]

while hq:
  v,w=heapq.heappop(hq)
  if v>d[w]:
    continue
  for i,j in g[w]:
    if d[i]>v+j:
      d[i]=v+j
      heapq.heappush(hq,(v+j,i))
      if i==1:
        print(v+j)
        exit()
0