結果

問題 No.2095 High Rise
ユーザー tobusakanatobusakana
提出日時 2022-11-25 22:06:13
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 232 ms / 2,000 ms
コード長 789 bytes
コンパイル時間 452 ms
コンパイル使用メモリ 86,812 KB
実行使用メモリ 86,744 KB
最終ジャッジ日時 2023-07-25 10:11:05
合計ジャッジ時間 7,134 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,212 KB
testcase_01 AC 74 ms
71,072 KB
testcase_02 AC 74 ms
71,360 KB
testcase_03 AC 74 ms
71,340 KB
testcase_04 AC 77 ms
71,120 KB
testcase_05 AC 76 ms
71,260 KB
testcase_06 AC 74 ms
71,432 KB
testcase_07 AC 74 ms
71,448 KB
testcase_08 AC 75 ms
71,340 KB
testcase_09 AC 76 ms
70,984 KB
testcase_10 AC 75 ms
71,072 KB
testcase_11 AC 76 ms
71,416 KB
testcase_12 AC 85 ms
76,172 KB
testcase_13 AC 83 ms
76,528 KB
testcase_14 AC 85 ms
76,316 KB
testcase_15 AC 85 ms
76,548 KB
testcase_16 AC 83 ms
76,308 KB
testcase_17 AC 104 ms
77,608 KB
testcase_18 AC 100 ms
77,924 KB
testcase_19 AC 86 ms
76,364 KB
testcase_20 AC 101 ms
77,684 KB
testcase_21 AC 117 ms
78,704 KB
testcase_22 AC 213 ms
86,716 KB
testcase_23 AC 215 ms
86,708 KB
testcase_24 AC 214 ms
86,712 KB
testcase_25 AC 232 ms
86,744 KB
testcase_26 AC 212 ms
86,740 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