結果

問題 No.2095 High Rise
ユーザー minimumminimum
提出日時 2022-10-07 21:59:10
言語 PyPy3
(7.3.15)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 824 bytes
コンパイル時間 277 ms
コンパイル使用メモリ 87,136 KB
実行使用メモリ 311,556 KB
最終ジャッジ日時 2023-09-03 02:05:37
合計ジャッジ時間 15,254 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,168 KB
testcase_01 AC 73 ms
71,352 KB
testcase_02 AC 72 ms
71,380 KB
testcase_03 AC 72 ms
71,200 KB
testcase_04 AC 74 ms
71,184 KB
testcase_05 AC 75 ms
71,384 KB
testcase_06 AC 75 ms
71,176 KB
testcase_07 AC 74 ms
71,320 KB
testcase_08 AC 75 ms
70,960 KB
testcase_09 AC 73 ms
71,288 KB
testcase_10 AC 75 ms
71,388 KB
testcase_11 AC 75 ms
70,964 KB
testcase_12 AC 118 ms
78,256 KB
testcase_13 AC 117 ms
77,956 KB
testcase_14 AC 130 ms
79,244 KB
testcase_15 AC 119 ms
78,412 KB
testcase_16 AC 115 ms
78,052 KB
testcase_17 AC 273 ms
103,232 KB
testcase_18 AC 217 ms
94,260 KB
testcase_19 AC 143 ms
81,964 KB
testcase_20 AC 295 ms
105,376 KB
testcase_21 AC 499 ms
133,092 KB
testcase_22 AC 1,900 ms
310,984 KB
testcase_23 TLE -
testcase_24 AC 1,832 ms
310,664 KB
testcase_25 AC 1,849 ms
310,824 KB
testcase_26 AC 1,857 ms
311,556 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappop, heappush
import sys
input = sys.stdin.readline


INF = 10 ** 18 + 1
N, M = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(N)]
V = N * (M + 1)
edges = [[] for _ in range(V)]
for i in range(N):
    for j in range(M):
        edges[N * M + i].append((i * M + j, A[i][j]))
        edges[i * M + j].append((N * M + i, 0))
for i in range(N - 1):
    for j in range(M):
        edges[i * M + j].append(((i + 1) * M + j, A[i + 1][j]))


S = N * M
dist = [INF] * V
dist[S] = 0
hq = [(0, S)]
done = [False] * V
while hq:
    _, now = heappop(hq)
    if done[now]:
        continue
    done[now] = True
    for nxt, cost in edges[now]:
        if dist[nxt] > dist[now] + cost:
            dist[nxt] = dist[now] + cost
            heappush(hq, (dist[nxt], nxt))

print(dist[-1])
0