結果

問題 No.595 登山
ユーザー uenokuuenoku
提出日時 2017-11-12 17:20:08
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 80 ms / 1,500 ms
コード長 648 bytes
コンパイル時間 1,724 ms
コンパイル使用メモリ 164,860 KB
実行使用メモリ 8,184 KB
最終ジャッジ日時 2023-08-16 10:58:21
合計ジャッジ時間 4,299 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,444 KB
testcase_01 AC 2 ms
6,476 KB
testcase_02 AC 3 ms
7,708 KB
testcase_03 AC 3 ms
6,504 KB
testcase_04 AC 56 ms
8,180 KB
testcase_05 AC 18 ms
7,340 KB
testcase_06 AC 48 ms
7,820 KB
testcase_07 AC 7 ms
7,444 KB
testcase_08 AC 11 ms
6,820 KB
testcase_09 AC 48 ms
8,092 KB
testcase_10 AC 34 ms
8,184 KB
testcase_11 AC 31 ms
7,272 KB
testcase_12 AC 7 ms
6,524 KB
testcase_13 AC 16 ms
8,020 KB
testcase_14 AC 36 ms
7,996 KB
testcase_15 AC 36 ms
8,008 KB
testcase_16 AC 36 ms
8,008 KB
testcase_17 AC 36 ms
8,008 KB
testcase_18 AC 37 ms
8,060 KB
testcase_19 AC 78 ms
7,972 KB
testcase_20 AC 79 ms
8,032 KB
testcase_21 AC 78 ms
8,000 KB
testcase_22 AC 78 ms
8,024 KB
testcase_23 AC 78 ms
8,036 KB
testcase_24 AC 3 ms
7,500 KB
testcase_25 AC 3 ms
6,992 KB
testcase_26 AC 80 ms
7,992 KB
testcase_27 AC 59 ms
8,032 KB
testcase_28 AC 60 ms
8,024 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
int main()
{
    lli n, p;
    cin >> n >> p;
    lli dp[2][200009] = {};
    lli h[200005];
    rep(i, n) cin >> h[i];
    dp[0][0] = 0;
    for (int i = 1; i < n; i++) {
        dp[0][i] = min(min(dp[0][i - 1], dp[1][i - 1]) + p, dp[0][i - 1] + max(h[i] - h[i - 1], 0LL));
        dp[1][i] = min(min(dp[0][i - 1], dp[1][i - 1]) + p, (i != 1 ? dp[1][i - 1] + max(h[i - 1] - h[i], 0LL) : 1000000000000000));
    }
    cout << min(dp[0][n - 1], dp[1][n - 1]) << endl;
    ;
}
0