結果

問題 No.595 登山
ユーザー nisizawanisizawa
提出日時 2017-12-15 19:18:32
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 630 ms / 1,500 ms
コード長 391 bytes
コンパイル時間 152 ms
コンパイル使用メモリ 10,852 KB
実行使用メモリ 52,156 KB
最終ジャッジ日時 2023-08-21 06:44:52
合計ジャッジ時間 13,358 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,856 KB
testcase_01 AC 16 ms
7,808 KB
testcase_02 AC 15 ms
7,852 KB
testcase_03 AC 15 ms
7,852 KB
testcase_04 AC 589 ms
47,488 KB
testcase_05 AC 171 ms
18,828 KB
testcase_06 AC 502 ms
42,728 KB
testcase_07 AC 62 ms
11,288 KB
testcase_08 AC 89 ms
13,404 KB
testcase_09 AC 498 ms
43,120 KB
testcase_10 AC 348 ms
30,712 KB
testcase_11 AC 311 ms
29,796 KB
testcase_12 AC 54 ms
10,796 KB
testcase_13 AC 151 ms
17,256 KB
testcase_14 AC 571 ms
39,444 KB
testcase_15 AC 570 ms
39,372 KB
testcase_16 AC 588 ms
39,448 KB
testcase_17 AC 579 ms
39,244 KB
testcase_18 AC 573 ms
39,432 KB
testcase_19 AC 626 ms
51,960 KB
testcase_20 AC 613 ms
51,976 KB
testcase_21 AC 627 ms
51,920 KB
testcase_22 AC 630 ms
52,036 KB
testcase_23 AC 608 ms
52,156 KB
testcase_24 AC 16 ms
7,788 KB
testcase_25 AC 15 ms
7,800 KB
testcase_26 AC 628 ms
52,056 KB
testcase_27 AC 617 ms
50,160 KB
testcase_28 AC 615 ms
50,168 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, p = map(int, input().split())
h_ls = [int(h) for h in input().split()]

memo = [[0, p] for i in range(n)]
for i in range(1, n):
    c0 = memo[i - 1][0]
    c1 = memo[i - 1][1]
    cost_0 = max(h_ls[i] - h_ls[i - 1], 0)
    cost_1 = max(h_ls[i - 1] - h_ls[i], 0)
    
    memo[i][0] = min(c0 + cost_0, c0 + p, c1 + p)
    memo[i][1] = min(c1 + cost_1, c1 + p, c0 + p)

print(min(memo[-1]))
0