結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
55,728 KB
testcase_01 AC 44 ms
55,728 KB
testcase_02 AC 44 ms
55,728 KB
testcase_03 AC 412 ms
177,452 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 397 ms
177,180 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 43 ms
55,728 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 44 ms
55,728 KB
testcase_14 WA -
testcase_15 AC 169 ms
98,208 KB
testcase_16 AC 107 ms
79,624 KB
testcase_17 AC 145 ms
88,476 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 284 ms
131,116 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 43 ms
55,728 KB
testcase_25 AC 44 ms
55,728 KB
testcase_26 AC 44 ms
55,728 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, min(abs(h-ai)+abs(w-bi),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