結果

問題 No.595 登山
ユーザー nanophoto12
提出日時 2017-11-26 19:19:53
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 970 bytes
コンパイル時間 1,695 ms
コンパイル使用メモリ 92,604 KB
実行使用メモリ 12,440 KB
最終ジャッジ日時 2024-11-27 11:43:23
合計ジャッジ時間 4,415 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 2
other AC * 9 WA * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cmath>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <functional>
#include <queue>
#include <iostream>
#include <string.h>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdint>
#include <climits>
#include <unordered_set>
#include <sstream>
#include <stack>

using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> t3;

ll dp[2][2000010];

int main(void) {
    ll n,p;
    cin >> n >> p;
    vector<ll> hs;
    hs.assign(n+1,0);
    for(int i = 0;i < n;i++)
    {
        cin >> hs[i];
    }
    hs[n] = hs[n-1];
    dp[0][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, dp[0][i-1] + max(hs[i]-hs[i-1],0LL));
        dp[1][i] = min(min(dp[0][i-1],dp[1][i-1]) + p, dp[1][i-1] + max(hs[i-1]-hs[i],0LL));
    }
    auto result = min(dp[0][n], dp[1][n]);
    cout << result << endl;
    return 0;
}
0