結果

問題 No.2095 High Rise
ユーザー minimumminimum
提出日時 2022-10-07 21:50:55
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 802 bytes
コンパイル時間 849 ms
コンパイル使用メモリ 87,272 KB
実行使用メモリ 374,768 KB
最終ジャッジ日時 2023-09-03 01:31:08
合計ジャッジ時間 18,292 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,140 KB
testcase_01 AC 76 ms
70,956 KB
testcase_02 AC 76 ms
70,748 KB
testcase_03 AC 75 ms
70,948 KB
testcase_04 AC 74 ms
71,248 KB
testcase_05 AC 75 ms
70,872 KB
testcase_06 AC 74 ms
70,960 KB
testcase_07 AC 76 ms
71,140 KB
testcase_08 AC 73 ms
71,140 KB
testcase_09 AC 75 ms
71,252 KB
testcase_10 AC 78 ms
70,956 KB
testcase_11 AC 78 ms
70,952 KB
testcase_12 AC 126 ms
78,056 KB
testcase_13 AC 124 ms
78,212 KB
testcase_14 AC 131 ms
79,372 KB
testcase_15 AC 124 ms
78,712 KB
testcase_16 AC 120 ms
78,180 KB
testcase_17 AC 314 ms
110,076 KB
testcase_18 AC 256 ms
98,132 KB
testcase_19 AC 163 ms
82,932 KB
testcase_20 AC 368 ms
113,076 KB
testcase_21 AC 584 ms
147,956 KB
testcase_22 TLE -
testcase_23 TLE -
testcase_24 TLE -
testcase_25 TLE -
testcase_26 TLE -
権限があれば一括ダウンロードができます

ソースコード

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