結果

問題 No.595 登山
ユーザー TAISA_TAISA_
提出日時 2019-12-15 23:54:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 934 bytes
コンパイル時間 1,408 ms
コンパイル使用メモリ 167,332 KB
実行使用メモリ 8,056 KB
最終ジャッジ日時 2023-09-15 15:54:48
合計ジャッジ時間 3,151 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 WA -
testcase_27 AC 23 ms
7,856 KB
testcase_28 AC 23 ms
7,804 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, p;
    cin >> n >> p;
    vector<ll> h(n);
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }
    vector<ll> dp0(n, LINF), dp1(n, LINF);
    dp0[1] = min(p, max(0LL, h[1] - h[0])), dp1[1] = p;
    for (int i = 2; i < n; i++) {
        chmin(dp0[i], dp1[i - 1] + p);
        chmin(dp1[i], dp0[i - 1] + p);
        chmin(dp0[i], dp0[i - 1] + max(0LL, h[i] - h[i - 1]));
        chmin(dp1[i], dp1[i - 1] + max(0LL, h[i - 1] - h[i]));
    }
    cout << min(dp0[n - 1], dp1[n - 1]) << endl;
}
0