結果
| 問題 |
No.2695 Warp Zone
|
| コンテスト | |
| ユーザー |
mymelochan
|
| 提出日時 | 2024-03-22 21:51:17 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 606 ms / 2,000 ms |
| コード長 | 1,226 bytes |
| コンパイル時間 | 447 ms |
| コンパイル使用メモリ | 82,340 KB |
| 実行使用メモリ | 206,080 KB |
| 最終ジャッジ日時 | 2024-09-30 11:19:57 |
| 合計ジャッジ時間 | 8,200 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 24 |
ソースコード
#############################################################
import sys
sys.setrecursionlimit(10**7)
from heapq import heappop,heappush
from collections import deque,defaultdict,Counter
from bisect import bisect_left, bisect_right
from itertools import product,combinations,permutations
ipt = sys.stdin.readline
def iin():
return int(ipt())
def lmin():
return list(map(int,ipt().split()))
MOD = 998244353
#############################################################
H,W,N = lmin()
L = [lmin() for _ in range(N)]
d = defaultdict(int)
d[(1,1)] = 0
d[(H,W)] = 1
cnt = 2
S = [(1,1),(H,W)]
for a,b,c,D in L:
d[(a,b)] = cnt
S.append((a,b))
cnt += 1
d[(c,D)] = cnt
S.append((c,D))
cnt += 1
G = [[] for _ in range(cnt)]
for a,b,c,D in L:
G[d[(a,b)]].append((d[(c,D)],1))
for i in range(cnt):
i1,j1 = S[i]
for j in range(cnt):
if i==j:
continue
i2,j2 = S[j]
G[i].append((j,abs(i1-i2)+abs(j1-j2)))
inf = 1<<60
hq = [(0,0)]
cost = [inf]*cnt
cost[0] = 0
while hq:
cur,c1 = heappop(hq)
for nxt,c2 in G[cur]:
if c1+c2 >= cost[nxt]:
continue
cost[nxt] = c1+c2
heappush(hq,(nxt,c1+c2))
print(cost[1])
mymelochan