結果

問題 No.595 登山
ユーザー TAISA_TAISA_
提出日時 2019-12-15 23:56:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 31 ms / 1,500 ms
コード長 968 bytes
コンパイル時間 1,513 ms
コンパイル使用メモリ 167,116 KB
実行使用メモリ 7,836 KB
最終ジャッジ日時 2023-09-15 15:54:58
合計ジャッジ時間 3,267 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 24 ms
7,556 KB
testcase_05 AC 7 ms
4,412 KB
testcase_06 AC 21 ms
6,976 KB
testcase_07 AC 4 ms
4,380 KB
testcase_08 AC 5 ms
4,376 KB
testcase_09 AC 21 ms
7,020 KB
testcase_10 AC 15 ms
5,732 KB
testcase_11 AC 14 ms
5,488 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 8 ms
4,380 KB
testcase_14 AC 19 ms
7,816 KB
testcase_15 AC 19 ms
7,820 KB
testcase_16 AC 19 ms
7,812 KB
testcase_17 AC 19 ms
7,828 KB
testcase_18 AC 19 ms
7,732 KB
testcase_19 AC 30 ms
7,756 KB
testcase_20 AC 29 ms
7,836 KB
testcase_21 AC 30 ms
7,836 KB
testcase_22 AC 29 ms
7,732 KB
testcase_23 AC 29 ms
7,752 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 31 ms
7,836 KB
testcase_27 AC 23 ms
7,836 KB
testcase_28 AC 24 ms
7,816 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], min(dp0[i - 1], dp1[i - 1]) + p);
        chmin(dp1[i], min(dp1[i - 1], 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