結果

問題 No.2695 Warp Zone
ユーザー PNJPNJ
提出日時 2024-03-22 22:58:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 332 ms / 2,000 ms
コード長 888 bytes
コンパイル時間 194 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 117,096 KB
最終ジャッジ日時 2024-03-22 22:58:25
合計ジャッジ時間 5,873 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
53,460 KB
testcase_01 AC 40 ms
53,460 KB
testcase_02 AC 41 ms
53,460 KB
testcase_03 AC 319 ms
116,596 KB
testcase_04 AC 299 ms
113,008 KB
testcase_05 AC 332 ms
113,128 KB
testcase_06 AC 312 ms
116,216 KB
testcase_07 AC 320 ms
117,096 KB
testcase_08 AC 55 ms
64,332 KB
testcase_09 AC 196 ms
88,504 KB
testcase_10 AC 40 ms
53,460 KB
testcase_11 AC 163 ms
80,212 KB
testcase_12 AC 223 ms
94,212 KB
testcase_13 AC 39 ms
53,460 KB
testcase_14 AC 246 ms
99,452 KB
testcase_15 AC 192 ms
87,252 KB
testcase_16 AC 145 ms
79,332 KB
testcase_17 AC 160 ms
82,048 KB
testcase_18 AC 279 ms
104,948 KB
testcase_19 AC 52 ms
62,348 KB
testcase_20 AC 261 ms
101,512 KB
testcase_21 AC 242 ms
98,316 KB
testcase_22 AC 182 ms
85,724 KB
testcase_23 AC 240 ms
93,324 KB
testcase_24 AC 41 ms
53,460 KB
testcase_25 AC 40 ms
53,460 KB
testcase_26 AC 40 ms
53,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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])
0