結果

問題 No.2095 High Rise
ユーザー minimumminimum
提出日時 2022-10-07 21:47:05
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 977 bytes
コンパイル時間 290 ms
コンパイル使用メモリ 86,752 KB
実行使用メモリ 499,968 KB
最終ジャッジ日時 2023-09-03 01:20:48
合計ジャッジ時間 9,399 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
75,868 KB
testcase_01 AC 80 ms
71,192 KB
testcase_02 AC 79 ms
71,408 KB
testcase_03 AC 79 ms
71,288 KB
testcase_04 AC 79 ms
71,300 KB
testcase_05 AC 78 ms
71,428 KB
testcase_06 AC 81 ms
71,168 KB
testcase_07 AC 79 ms
71,424 KB
testcase_08 AC 78 ms
71,372 KB
testcase_09 AC 80 ms
71,320 KB
testcase_10 AC 81 ms
71,196 KB
testcase_11 AC 80 ms
71,436 KB
testcase_12 AC 149 ms
79,212 KB
testcase_13 AC 142 ms
78,832 KB
testcase_14 AC 152 ms
80,824 KB
testcase_15 AC 146 ms
79,520 KB
testcase_16 AC 137 ms
78,544 KB
testcase_17 AC 469 ms
127,708 KB
testcase_18 AC 342 ms
110,392 KB
testcase_19 AC 194 ms
85,480 KB
testcase_20 AC 518 ms
132,216 KB
testcase_21 AC 908 ms
183,664 KB
testcase_22 TLE -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappop, heappush


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


dist = [INF] * (2 * N * M)
dist[0] = 0
hq = [(0, 0)]
done = [False] * (2 * N * M)
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[N * M - 1])
0