結果
| 問題 | No.2695 Warp Zone | 
| コンテスト | |
| ユーザー |  PNJ | 
| 提出日時 | 2024-03-22 22:58:13 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 256 ms / 2,000 ms | 
| コード長 | 888 bytes | 
| コンパイル時間 | 175 ms | 
| コンパイル使用メモリ | 82,624 KB | 
| 実行使用メモリ | 117,676 KB | 
| 最終ジャッジ日時 | 2024-09-30 12:20:37 | 
| 合計ジャッジ時間 | 4,562 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 24 | 
ソースコード
import heapq
def f(s, n, edge):
    dist = [float("Inf")]*n
    dist[s] = 0
    hq = [[0,s]]
    heapq.heapify(hq)
    while len(hq) > 0:
        d,i = heapq.heappop(hq)
        if dist[i] < d:
            continue
        for j,d_1 in edge[i]:
            if dist[j] > (dist[i] + d_1):
                dist[j] = dist[i] + d_1
                heapq.heappush(hq, [dist[j],j])
    return dist
H,W,N = map(int,input().split())
s = 0
g = 2*N + 1
G = [[] for i in range(2*N+2)]
G[s].append((g,H+W-2))
X = [[]]
for i in range(1,N+1):
  a,b,c,d = map(int,input().split())
  X.append((a,b,c,d))
  u,v = i,i+N
  G[0].append((u,a+b-2))
  G[u].append((v,1))
  G[v].append((g,H+W-c-d))
for u in range(1,N):
  for v in range(u+1,N+1):
    a,b,c,d = X[u]
    aa,bb,cc,dd = X[v]
    G[u+N].append((v,abs(aa-c)+abs(bb-d)))
    G[v+N].append((u,abs(a-cc)+abs(b-dd)))
dist = f(0,2*N+2,G)
print(dist[g])
            
            
            
        