結果

問題 No.595 登山
ユーザー nisizawanisizawa
提出日時 2017-12-15 19:18:32
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 734 ms / 1,500 ms
コード長 391 bytes
コンパイル時間 203 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 54,636 KB
最終ジャッジ日時 2024-05-08 12:15:04
合計ジャッジ時間 14,331 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,752 KB
testcase_01 AC 29 ms
10,752 KB
testcase_02 AC 28 ms
10,752 KB
testcase_03 AC 28 ms
10,624 KB
testcase_04 AC 680 ms
50,248 KB
testcase_05 AC 204 ms
21,604 KB
testcase_06 AC 563 ms
45,484 KB
testcase_07 AC 78 ms
13,952 KB
testcase_08 AC 111 ms
16,044 KB
testcase_09 AC 559 ms
45,892 KB
testcase_10 AC 402 ms
33,400 KB
testcase_11 AC 359 ms
32,516 KB
testcase_12 AC 71 ms
13,568 KB
testcase_13 AC 178 ms
19,772 KB
testcase_14 AC 651 ms
42,008 KB
testcase_15 AC 652 ms
41,948 KB
testcase_16 AC 648 ms
41,892 KB
testcase_17 AC 653 ms
42,148 KB
testcase_18 AC 670 ms
42,004 KB
testcase_19 AC 707 ms
54,604 KB
testcase_20 AC 700 ms
54,504 KB
testcase_21 AC 710 ms
54,628 KB
testcase_22 AC 711 ms
54,608 KB
testcase_23 AC 725 ms
54,636 KB
testcase_24 AC 28 ms
10,752 KB
testcase_25 AC 26 ms
10,880 KB
testcase_26 AC 734 ms
54,584 KB
testcase_27 AC 690 ms
51,532 KB
testcase_28 AC 692 ms
51,420 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