結果

問題 No.595 登山
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2017-11-12 07:11:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 25 ms / 1,500 ms
コード長 1,724 bytes
コンパイル時間 1,380 ms
コンパイル使用メモリ 168,176 KB
実行使用メモリ 8,252 KB
最終ジャッジ日時 2024-05-03 19:01:04
合計ジャッジ時間 2,926 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,004 KB
testcase_01 AC 3 ms
7,008 KB
testcase_02 AC 2 ms
7,268 KB
testcase_03 AC 3 ms
6,940 KB
testcase_04 AC 19 ms
8,036 KB
testcase_05 AC 7 ms
7,012 KB
testcase_06 AC 18 ms
7,848 KB
testcase_07 AC 4 ms
6,948 KB
testcase_08 AC 4 ms
6,944 KB
testcase_09 AC 17 ms
7,864 KB
testcase_10 AC 12 ms
7,524 KB
testcase_11 AC 11 ms
7,280 KB
testcase_12 AC 4 ms
7,808 KB
testcase_13 AC 7 ms
7,272 KB
testcase_14 AC 16 ms
8,252 KB
testcase_15 AC 16 ms
8,132 KB
testcase_16 AC 16 ms
8,164 KB
testcase_17 AC 16 ms
8,036 KB
testcase_18 AC 16 ms
8,160 KB
testcase_19 AC 23 ms
8,036 KB
testcase_20 AC 22 ms
8,124 KB
testcase_21 AC 23 ms
8,040 KB
testcase_22 AC 23 ms
8,036 KB
testcase_23 AC 23 ms
8,164 KB
testcase_24 AC 3 ms
7,696 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 25 ms
8,180 KB
testcase_27 AC 18 ms
8,128 KB
testcase_28 AC 19 ms
8,164 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     
    /   \     | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/



typedef long long ll;
#define INF 1LL<<60
int N; ll P, H[201010];
ll dp[201010][2];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> P;
    rep(i, 0, N) cin >> H[i];

    rep(i, 0, 201010) rep(dir, 0, 2) dp[i][dir] = INF;
    dp[0][0] = 0;

    rep(i, 0, N - 1) {
        // ->を伸ばす遷移
        dp[i + 1][0] = min(dp[i + 1][0], dp[i][0] + min(P, max(H[i + 1] - H[i], 0LL)));
        
        // 今まで->だったのを<-とする遷移
        dp[i + 1][1] = min(dp[i + 1][1], dp[i][0] + P);

        // <-を伸ばす遷移
        dp[i + 1][1] = min(dp[i + 1][1], dp[i][1] + min(P, max(H[i] - H[i + 1], 0LL)));

        // 今まで<-だったのを->とする遷移
        dp[i + 1][0] = min(dp[i + 1][0], dp[i][1] + P);
    }

    ll ans = min(dp[N - 1][0], dp[N - 1][1]);
    cout << ans << endl;
}
0