結果

問題 No.2695 Warp Zone
ユーザー mutualnsmutualns
提出日時 2024-03-23 06:29:55
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,146 bytes
コンパイル時間 273 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 197,112 KB
最終ジャッジ日時 2024-03-23 06:30:00
合計ジャッジ時間 4,193 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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
    k=dist(wpt[i],wps[j])
    if 1+dist(wps[i],wps[j])<k:
      g[2*i+2].append([2*j+2,dist(wps[i],wps[j])])
    k=dist(wpt[i],wpt[j])
    if 1+dist(wps[i],wpt[j])<k:
      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
  if w==1:
    print(v)
    exit()
  for i,j in g[w]:
    if d[i]>v+j:
      d[i]=v+j
      heapq.heappush(hq,(v+j,i))
0