結果

問題 No.595 登山
ユーザー nanophoto12nanophoto12
提出日時 2017-11-26 19:19:53
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 970 bytes
コンパイル時間 1,281 ms
コンパイル使用メモリ 92,852 KB
実行使用メモリ 8,064 KB
最終ジャッジ日時 2024-05-05 13:50:27
合計ジャッジ時間 3,549 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
5,376 KB
testcase_02 WA -
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 55 ms
7,552 KB
testcase_05 WA -
testcase_06 AC 48 ms
6,912 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 34 ms
5,888 KB
testcase_11 AC 29 ms
5,632 KB
testcase_12 AC 6 ms
5,376 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 36 ms
7,808 KB
testcase_18 WA -
testcase_19 AC 78 ms
7,808 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 2 ms
5,376 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 58 ms
7,808 KB
権限があれば一括ダウンロードができます

ソースコード

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