結果

問題 No.595 登山
ユーザー T1610T1610
提出日時 2020-07-13 14:28:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,008 bytes
コンパイル時間 2,049 ms
コンパイル使用メモリ 200,920 KB
実行使用メモリ 8,100 KB
最終ジャッジ日時 2023-08-07 12:32:35
合計ジャッジ時間 5,240 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 1 ms
4,384 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,384 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 81 ms
7,828 KB
testcase_27 AC 61 ms
7,788 KB
testcase_28 AC 61 ms
7,844 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

int main(){
    ll n, p;
    cin >> n >> p;
    vl h(n);
    rep(i, n) cin >> h[i];
    vl left(n);
    iota(all(left), 0);
    REP(i, 1, n) if(h[i-1] <= h[i]) left[i] = left[i-1];
    vl dp(n, INF);
    dp[0] = 0LL;
    REP(i, 1, n) {
        chmin(dp[i], dp[i-1]+max(0LL, h[i]- h[i-1]));
        {
            int j = (left[i] == 0 ? 0 : left[i]-1);
            chmin(dp[i], dp[j]+p);
        }
    }
    cout << dp.back() << '\n';
    return 0;
}
0