結果

問題 No.595 登山
ユーザー t98slidert98slider
提出日時 2023-08-03 02:26:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 31 ms / 1,500 ms
コード長 624 bytes
コンパイル時間 1,725 ms
コンパイル使用メモリ 166,408 KB
実行使用メモリ 7,296 KB
最終ジャッジ日時 2024-04-21 02:02:31
合計ジャッジ時間 3,415 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 23 ms
6,912 KB
testcase_05 AC 7 ms
5,376 KB
testcase_06 AC 19 ms
6,528 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 4 ms
5,376 KB
testcase_09 AC 21 ms
6,656 KB
testcase_10 AC 15 ms
5,504 KB
testcase_11 AC 13 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 7 ms
5,376 KB
testcase_14 AC 17 ms
7,168 KB
testcase_15 AC 17 ms
7,168 KB
testcase_16 AC 18 ms
7,296 KB
testcase_17 AC 17 ms
7,168 KB
testcase_18 AC 17 ms
7,168 KB
testcase_19 AC 29 ms
7,168 KB
testcase_20 AC 29 ms
7,168 KB
testcase_21 AC 30 ms
7,168 KB
testcase_22 AC 30 ms
7,168 KB
testcase_23 AC 29 ms
7,168 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 31 ms
7,296 KB
testcase_27 AC 22 ms
7,168 KB
testcase_28 AC 23 ms
7,168 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, p;
    cin >> n >> p;
    vector<int> a(n);
    for(auto &&v : a) cin >> v;
    vector<ll> dp(n, 1ll << 60);
    vector<ll> dp2(n, 1ll << 60);
    dp[0] = 0;
    for(int i = 1; i < n; i++){
        dp[i] = min(dp[i], dp[i - 1] + min(p, max(0, a[i] - a[i - 1])));
        dp[i] = min(dp[i], dp2[i - 1] + p);
        dp2[i] = min(dp2[i], dp[i - 1] + p);
        dp2[i] = min(dp2[i], dp2[i - 1] + min(p, max(0, a[i - 1] - a[i])));
    }
    cout << min(dp[n - 1], dp2[n - 1]) << '\n';
}
0