結果

問題 No.2695 Warp Zone
ユーザー flygonflygon
提出日時 2024-03-22 22:14:25
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,129 bytes
コンパイル時間 176 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 177,836 KB
最終ジャッジ日時 2024-03-22 22:14:32
合計ジャッジ時間 6,807 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
55,600 KB
testcase_01 AC 45 ms
55,600 KB
testcase_02 AC 46 ms
55,600 KB
testcase_03 AC 432 ms
177,836 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 424 ms
177,304 KB
testcase_07 AC 474 ms
177,816 KB
testcase_08 WA -
testcase_09 AC 235 ms
106,656 KB
testcase_10 AC 48 ms
55,600 KB
testcase_11 AC 135 ms
83,972 KB
testcase_12 WA -
testcase_13 AC 46 ms
55,600 KB
testcase_14 AC 318 ms
131,736 KB
testcase_15 AC 176 ms
98,336 KB
testcase_16 AC 111 ms
79,620 KB
testcase_17 AC 149 ms
88,476 KB
testcase_18 AC 348 ms
152,600 KB
testcase_19 WA -
testcase_20 AC 362 ms
147,372 KB
testcase_21 AC 302 ms
130,988 KB
testcase_22 WA -
testcase_23 AC 234 ms
116,012 KB
testcase_24 AC 46 ms
55,600 KB
testcase_25 AC 48 ms
55,600 KB
testcase_26 AC 47 ms
55,600 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[j].append((i, 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