結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
55,600 KB
testcase_01 AC 45 ms
55,600 KB
testcase_02 AC 46 ms
55,600 KB
testcase_03 AC 410 ms
177,964 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 395 ms
177,176 KB
testcase_07 AC 422 ms
177,816 KB
testcase_08 WA -
testcase_09 AC 217 ms
106,784 KB
testcase_10 AC 45 ms
55,600 KB
testcase_11 AC 128 ms
84,100 KB
testcase_12 WA -
testcase_13 AC 45 ms
55,600 KB
testcase_14 AC 321 ms
131,864 KB
testcase_15 AC 173 ms
98,336 KB
testcase_16 AC 112 ms
79,620 KB
testcase_17 AC 140 ms
87,836 KB
testcase_18 AC 344 ms
152,600 KB
testcase_19 WA -
testcase_20 AC 305 ms
147,756 KB
testcase_21 AC 302 ms
130,988 KB
testcase_22 WA -
testcase_23 AC 227 ms
116,012 KB
testcase_24 AC 45 ms
55,600 KB
testcase_25 AC 46 ms
55,600 KB
testcase_26 AC 52 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+1))
    graph[i].append((n+1, abs(h-ci)+abs(w-di)))

graph[n].append((n+1, h+w-2))
#ダイクストラ法
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(d[n+1])
0