結果

問題 No.2095 High Rise
ユーザー kept1994kept1994
提出日時 2022-11-03 19:54:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 322 ms / 2,000 ms
コード長 937 bytes
コンパイル時間 363 ms
コンパイル使用メモリ 87,088 KB
実行使用メモリ 94,976 KB
最終ジャッジ日時 2023-09-25 03:43:22
合計ジャッジ時間 6,060 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,640 KB
testcase_01 AC 74 ms
71,632 KB
testcase_02 AC 72 ms
71,344 KB
testcase_03 AC 76 ms
71,540 KB
testcase_04 AC 75 ms
71,372 KB
testcase_05 AC 77 ms
71,344 KB
testcase_06 AC 75 ms
71,216 KB
testcase_07 AC 79 ms
71,440 KB
testcase_08 AC 78 ms
71,384 KB
testcase_09 AC 74 ms
71,376 KB
testcase_10 AC 70 ms
71,400 KB
testcase_11 AC 70 ms
71,440 KB
testcase_12 AC 80 ms
76,452 KB
testcase_13 AC 77 ms
76,664 KB
testcase_14 AC 81 ms
76,552 KB
testcase_15 AC 79 ms
76,644 KB
testcase_16 AC 78 ms
76,460 KB
testcase_17 AC 114 ms
79,232 KB
testcase_18 AC 107 ms
78,348 KB
testcase_19 AC 89 ms
76,432 KB
testcase_20 AC 113 ms
79,104 KB
testcase_21 AC 139 ms
81,612 KB
testcase_22 AC 311 ms
94,780 KB
testcase_23 AC 312 ms
94,960 KB
testcase_24 AC 314 ms
94,748 KB
testcase_25 AC 322 ms
94,976 KB
testcase_26 AC 317 ms
94,908 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
INF = 10 ** 16
def main():
    N, M = map(int, input().split())
    if N == 1:
        print(0)
        return
    G = []
    for _ in range(N):
        G.append(list(map(int, input().split())))
    ans = 0
    if M == 1:
        for i in range(N):
            ans += G[i][0]
        print(ans)
        return
    dp = [G[0]] + [[INF] * M for _ in range(N - 1)]
    tmp = sorted(G[0])
    mins = [tmp[0], tmp[1]]
    mins_next = []
    for i in range(1, N):
        for j in range(M):
            up = mins[0] if dp[i - 1][j] != mins[0] else mins[1]
            c = min(dp[i - 1][j] + G[i][j], up + G[i - 1][j] + G[i][j])
            dp[i][j] = c
            mins_next.append(c)
            mins_next.sort()
            mins_next = mins_next[:2]
        mins = mins_next
        mins_next = []
    # for i in range(N):
    #     print(dp[i])
    print(min(dp[-1]))
    return

if __name__ == '__main__':
    main()
0