結果

問題 No.2695 Warp Zone
ユーザー flygonflygon
提出日時 2024-03-22 22:25:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 239 ms / 2,000 ms
コード長 1,093 bytes
コンパイル時間 329 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 109,580 KB
最終ジャッジ日時 2024-03-22 22:25:09
合計ジャッジ時間 4,871 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
55,604 KB
testcase_01 AC 47 ms
55,604 KB
testcase_02 AC 46 ms
55,600 KB
testcase_03 AC 229 ms
109,452 KB
testcase_04 AC 218 ms
107,660 KB
testcase_05 AC 239 ms
107,532 KB
testcase_06 AC 222 ms
109,324 KB
testcase_07 AC 223 ms
109,580 KB
testcase_08 AC 60 ms
66,272 KB
testcase_09 AC 159 ms
87,816 KB
testcase_10 AC 45 ms
55,604 KB
testcase_11 AC 109 ms
79,476 KB
testcase_12 AC 194 ms
92,172 KB
testcase_13 AC 46 ms
55,604 KB
testcase_14 AC 173 ms
96,908 KB
testcase_15 AC 141 ms
85,896 KB
testcase_16 AC 106 ms
78,728 KB
testcase_17 AC 112 ms
79,488 KB
testcase_18 AC 188 ms
101,132 KB
testcase_19 AC 56 ms
64,188 KB
testcase_20 AC 195 ms
98,572 KB
testcase_21 AC 174 ms
96,140 KB
testcase_22 AC 126 ms
84,992 KB
testcase_23 AC 153 ms
91,404 KB
testcase_24 AC 44 ms
55,604 KB
testcase_25 AC 43 ms
55,604 KB
testcase_26 AC 44 ms
55,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(5*10**5)
input = sys.stdin.readline
from collections import defaultdict, deque, Counter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right
from math import gcd

h,w,n = map(int,input().split())
za = [list(map(int,input().split())) for i in range(n)]
graph = [[] for i in range(n+3)]
for i in range(n):
    ai,bi,ci,di = za[i]
    for j in range(n):
        if i == j: continue
        aj,bj,cj,dj = za[j]
        dis = abs(ci-aj) + abs(di-bj)
        graph[i].append((j, dis+1))
    graph[n].append((i, ai+bi-2))
    graph[i].append((n+1, abs(h-ci)+abs(w-di)+1))

#ダイクストラ法
def dijkstra(s,n): # sがスタート、nが頂点数
    INF = 10**15
    dist = [INF]*(n+1)
    que = [(0,s)]
    dist[s] = 0
    while que:
        c,crr = heappop(que)
        if c > dist[crr]: continue
        for nxt, cost in graph[crr]:
            if dist[crr] + cost < dist[nxt]:
                dist[nxt] = dist[crr] + cost
                heappush(que,(dist[nxt],nxt))
    return dist

d = dijkstra(n,n+2)

print(min(d[n+1], h+w-2))
0