結果

問題 No.595 登山
ユーザー face4face4
提出日時 2019-11-23 15:42:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 82 ms / 1,500 ms
コード長 573 bytes
コンパイル時間 805 ms
コンパイル使用メモリ 73,696 KB
実行使用メモリ 9,600 KB
最終ジャッジ日時 2024-04-19 14:42:56
合計ジャッジ時間 3,693 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 55 ms
9,216 KB
testcase_05 AC 17 ms
5,376 KB
testcase_06 AC 49 ms
8,448 KB
testcase_07 AC 6 ms
5,376 KB
testcase_08 AC 10 ms
5,376 KB
testcase_09 AC 49 ms
8,576 KB
testcase_10 AC 35 ms
6,784 KB
testcase_11 AC 30 ms
6,400 KB
testcase_12 AC 6 ms
5,376 KB
testcase_13 AC 16 ms
5,376 KB
testcase_14 AC 36 ms
9,600 KB
testcase_15 AC 38 ms
9,600 KB
testcase_16 AC 38 ms
9,344 KB
testcase_17 AC 37 ms
9,472 KB
testcase_18 AC 37 ms
9,472 KB
testcase_19 AC 79 ms
9,600 KB
testcase_20 AC 81 ms
9,472 KB
testcase_21 AC 78 ms
9,472 KB
testcase_22 AC 81 ms
9,600 KB
testcase_23 AC 79 ms
9,600 KB
testcase_24 AC 1 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 82 ms
9,472 KB
testcase_27 AC 61 ms
9,472 KB
testcase_28 AC 59 ms
9,600 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
using namespace std;

typedef long long ll;

int main(){
    int n;
    ll p;
    cin >> n >> p;
    ll h[n];
    for(int i = 0; i < n; i++)  cin >> h[i];
    vector<vector<ll>> dp(2, vector<ll>(n, 1ll<<60));
    dp[0][0] = dp[1][0] = 0;
    for(int i = 1; i < n; i++){
        dp[0][i] = min(min(dp[0][i-1],dp[1][i-1])+p, i==1 ? 1ll<<60 : dp[0][i-1]+max(0ll, h[i-1]-h[i]));
        dp[1][i] = min(min(dp[0][i-1],dp[1][i-1])+p, dp[1][i-1]+max(0ll, h[i]-h[i-1]));
    }
    cout << min(dp[0].back(), dp[1].back()) << endl;
    return 0;
}
0