結果

問題 No.2695 Warp Zone
ユーザー とりゐとりゐ
提出日時 2024-03-22 21:40:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,331 ms / 2,000 ms
コード長 943 bytes
コンパイル時間 232 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 426,832 KB
最終ジャッジ日時 2024-03-22 21:41:08
合計ジャッジ時間 13,843 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,460 KB
testcase_01 AC 39 ms
53,460 KB
testcase_02 AC 40 ms
53,460 KB
testcase_03 AC 1,331 ms
426,712 KB
testcase_04 AC 1,233 ms
413,656 KB
testcase_05 AC 1,227 ms
413,784 KB
testcase_06 AC 1,252 ms
423,388 KB
testcase_07 AC 1,252 ms
426,832 KB
testcase_08 AC 68 ms
70,432 KB
testcase_09 AC 398 ms
189,280 KB
testcase_10 AC 42 ms
53,460 KB
testcase_11 AC 173 ms
105,800 KB
testcase_12 AC 519 ms
240,496 KB
testcase_13 AC 41 ms
53,460 KB
testcase_14 AC 710 ms
288,736 KB
testcase_15 AC 335 ms
174,320 KB
testcase_16 AC 163 ms
101,428 KB
testcase_17 AC 246 ms
133,832 KB
testcase_18 AC 882 ms
341,864 KB
testcase_19 AC 63 ms
68,352 KB
testcase_20 AC 774 ms
312,568 KB
testcase_21 AC 710 ms
285,040 KB
testcase_22 AC 302 ms
163,764 KB
testcase_23 AC 480 ms
238,448 KB
testcase_24 AC 41 ms
53,460 KB
testcase_25 AC 40 ms
53,460 KB
testcase_26 AC 41 ms
53,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

H,W,N=map(int,input().split())
dic={}
dic[(1,1)]=0
dic[(H,W)]=1
num=2
pos=[(1,1),(H,W)]
abcd=[]
for i in range(N):
  a,b,c,d=map(int,input().split())
  if (a,b) not in dic:
    dic[(a,b)]=num
    pos.append((a,b))
    num+=1
  if (c,d) not in dic:
    dic[(c,d)]=num
    pos.append((c,d))
    num+=1
  abcd.append([a,b,c,d])

M=num
edge=[[] for i in range(M)]
for a,b,c,d in abcd:
  edge[dic[(a,b)]].append((dic[c,d],1))

for i in range(M):
  for j in range(M):
    xi,yi=pos[i]
    xj,yj=pos[j]
    edge[i].append([j,abs(xi-xj)+abs(yi-yj)])

from heapq import heappush, heappop
INF=10**18
def dijkstra(start,n):
  dist=[INF]*n
  hq=[(0,start)]
  dist[start]=0
  seen=[False]*n
  while hq:
    w,v=heappop(hq)
    if dist[v]<w:
      continue
    seen[v]=True
    for to,cost in edge[v]:
      if seen[to]==False and dist[v]+cost<dist[to]:
        dist[to]=dist[v]+cost
        heappush(hq,(dist[to],to))
  return dist

print(dijkstra(0,M)[1])
0