結果

問題 No.2095 High Rise
ユーザー kept1994kept1994
提出日時 2022-11-03 19:51:25
言語 PyPy3
(7.3.13)
結果
RE  
実行時間 -
コード長 822 bytes
コンパイル時間 643 ms
コンパイル使用メモリ 87,236 KB
実行使用メモリ 95,028 KB
最終ジャッジ日時 2023-09-25 03:40:35
合計ジャッジ時間 7,330 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,372 KB
testcase_01 AC 71 ms
71,468 KB
testcase_02 AC 73 ms
71,584 KB
testcase_03 AC 72 ms
71,360 KB
testcase_04 AC 74 ms
71,428 KB
testcase_05 AC 72 ms
71,584 KB
testcase_06 AC 72 ms
71,200 KB
testcase_07 RE -
testcase_08 AC 73 ms
71,292 KB
testcase_09 AC 71 ms
71,132 KB
testcase_10 AC 73 ms
71,224 KB
testcase_11 AC 73 ms
71,232 KB
testcase_12 AC 91 ms
76,568 KB
testcase_13 AC 81 ms
76,612 KB
testcase_14 AC 83 ms
76,708 KB
testcase_15 AC 83 ms
76,348 KB
testcase_16 AC 81 ms
76,520 KB
testcase_17 AC 116 ms
79,220 KB
testcase_18 AC 110 ms
78,648 KB
testcase_19 AC 88 ms
76,548 KB
testcase_20 AC 112 ms
79,104 KB
testcase_21 AC 149 ms
81,528 KB
testcase_22 AC 321 ms
94,760 KB
testcase_23 AC 316 ms
95,028 KB
testcase_24 AC 319 ms
94,748 KB
testcase_25 AC 322 ms
94,828 KB
testcase_26 AC 317 ms
94,968 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())))
    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