結果

問題 No.2095 High Rise
ユーザー roarisroaris
提出日時 2022-10-07 22:07:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 219 ms / 2,000 ms
コード長 590 bytes
コンパイル時間 799 ms
コンパイル使用メモリ 87,240 KB
実行使用メモリ 87,044 KB
最終ジャッジ日時 2023-09-03 12:45:15
合計ジャッジ時間 4,922 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
71,300 KB
testcase_01 AC 62 ms
71,376 KB
testcase_02 AC 62 ms
71,624 KB
testcase_03 AC 61 ms
71,284 KB
testcase_04 AC 63 ms
71,404 KB
testcase_05 AC 61 ms
71,336 KB
testcase_06 AC 64 ms
71,436 KB
testcase_07 AC 63 ms
71,680 KB
testcase_08 AC 63 ms
71,240 KB
testcase_09 AC 63 ms
71,436 KB
testcase_10 AC 64 ms
71,404 KB
testcase_11 AC 69 ms
71,148 KB
testcase_12 AC 81 ms
76,848 KB
testcase_13 AC 79 ms
76,776 KB
testcase_14 AC 82 ms
76,668 KB
testcase_15 AC 82 ms
76,504 KB
testcase_16 AC 78 ms
76,560 KB
testcase_17 AC 107 ms
78,336 KB
testcase_18 AC 98 ms
77,968 KB
testcase_19 AC 86 ms
76,680 KB
testcase_20 AC 103 ms
77,832 KB
testcase_21 AC 123 ms
79,712 KB
testcase_22 AC 216 ms
86,852 KB
testcase_23 AC 213 ms
86,936 KB
testcase_24 AC 209 ms
86,876 KB
testcase_25 AC 219 ms
87,044 KB
testcase_26 AC 216 ms
86,932 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N, M = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(N)]

if N==1:
    exit(print(0))
    
dp = a[0][:]

for i in range(1, N):
    ndp = [10**18]*M
    
    for j in range(M):
        ndp[j] = min(ndp[j], dp[j]+a[i][j])
    
    ml = 10**18
    
    for j in range(M):
        ndp[j] = min(ndp[j], ml+a[i-1][j]+a[i][j])
        ml = min(ml, dp[j])
    
    mr = 10**18
    
    for j in range(M-1, -1, -1):
        ndp[j] = min(ndp[j], mr+a[i-1][j]+a[i][j])
        mr = min(mr, dp[j])
    
    dp = ndp

print(min(dp))
0