結果

問題 No.2095 High Rise
ユーザー tobusakanatobusakana
提出日時 2022-11-25 22:06:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 188 ms / 2,000 ms
コード長 789 bytes
コンパイル時間 339 ms
コンパイル使用メモリ 82,300 KB
実行使用メモリ 85,632 KB
最終ジャッジ日時 2024-04-10 03:14:46
合計ジャッジ時間 4,528 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
52,480 KB
testcase_01 AC 39 ms
52,480 KB
testcase_02 AC 42 ms
52,224 KB
testcase_03 AC 37 ms
52,904 KB
testcase_04 AC 37 ms
53,072 KB
testcase_05 AC 36 ms
52,068 KB
testcase_06 AC 37 ms
52,548 KB
testcase_07 AC 37 ms
52,760 KB
testcase_08 AC 36 ms
52,488 KB
testcase_09 AC 36 ms
52,128 KB
testcase_10 AC 37 ms
52,940 KB
testcase_11 AC 36 ms
53,212 KB
testcase_12 AC 45 ms
62,412 KB
testcase_13 AC 43 ms
62,040 KB
testcase_14 AC 45 ms
62,412 KB
testcase_15 AC 44 ms
61,604 KB
testcase_16 AC 41 ms
60,392 KB
testcase_17 AC 67 ms
76,624 KB
testcase_18 AC 63 ms
77,012 KB
testcase_19 AC 49 ms
64,824 KB
testcase_20 AC 67 ms
76,352 KB
testcase_21 AC 81 ms
77,388 KB
testcase_22 AC 169 ms
85,248 KB
testcase_23 AC 168 ms
85,072 KB
testcase_24 AC 166 ms
85,004 KB
testcase_25 AC 188 ms
85,632 KB
testcase_26 AC 170 ms
85,360 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline = sys.stdin.readline
N,M = map(int,readline().split())
if N == 1:
    print(0)
    exit(0)
A = [list(map(int,readline().split())) for i in range(N)]
INF = 1 << 60

dp = [INF] * M # 現在i番目が壊されている状態のときの最小コスト
best = INF # その階にいるときの最小コスト
for j in range(M):
    dp[j] = A[0][j]
    if best > dp[j]:
        best = dp[j]
        
for i in range(1, N):
    new_dp = [INF] * M
    next_best = INF
    for j in range(M):
        new_dp[j] = min(dp[j] + A[i][j], best + A[i - 1][j] + A[i][j])
#        print("j",j,"で上がるときのコスト",new_dp[j])
        if next_best > new_dp[j]:
            next_best = new_dp[j]
    dp = new_dp
    best = next_best
#    print("i",i,"dp",dp)
    
print(min(dp))
0