結果
問題 | No.2695 Warp Zone |
ユーザー |
![]() |
提出日時 | 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 syssys.setrecursionlimit(10**7)from heapq import heappop,heappushfrom collections import deque,defaultdict,Counterfrom bisect import bisect_left, bisect_rightfrom itertools import product,combinations,permutationsipt = sys.stdin.readlinedef 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)] = 0d[(H,W)] = 1cnt = 2S = [(1,1),(H,W)]for a,b,c,D in L:d[(a,b)] = cntS.append((a,b))cnt += 1d[(c,D)] = cntS.append((c,D))cnt += 1G = [[] 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:continuei2,j2 = S[j]G[i].append((j,abs(i1-i2)+abs(j1-j2)))inf = 1<<60hq = [(0,0)]cost = [inf]*cntcost[0] = 0while hq:cur,c1 = heappop(hq)for nxt,c2 in G[cur]:if c1+c2 >= cost[nxt]:continuecost[nxt] = c1+c2heappush(hq,(nxt,c1+c2))print(cost[1])