結果

問題 No.595 登山
ユーザー nanophoto12nanophoto12
提出日時 2017-11-26 19:19:53
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 970 bytes
コンパイル時間 2,143 ms
コンパイル使用メモリ 93,120 KB
実行使用メモリ 10,520 KB
最終ジャッジ日時 2023-08-18 07:58:17
合計ジャッジ時間 5,781 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
5,572 KB
testcase_02 WA -
testcase_03 AC 2 ms
5,372 KB
testcase_04 AC 58 ms
10,068 KB
testcase_05 WA -
testcase_06 AC 52 ms
9,780 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 36 ms
9,044 KB
testcase_11 AC 32 ms
8,744 KB
testcase_12 AC 6 ms
5,516 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 38 ms
10,328 KB
testcase_18 WA -
testcase_19 AC 79 ms
10,220 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 60 ms
10,220 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