結果

問題 No.595 登山
ユーザー Kutimoti_TKutimoti_T
提出日時 2018-06-07 17:30:37
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 649 bytes
コンパイル時間 1,252 ms
コンパイル使用メモリ 147,072 KB
実行使用メモリ 6,520 KB
最終ジャッジ日時 2023-09-12 23:06:51
合計ジャッジ時間 4,384 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 31 ms
4,672 KB
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 2 ms
4,380 KB
testcase_26 AC 80 ms
6,248 KB
testcase_27 AC 60 ms
6,212 KB
testcase_28 AC 60 ms
6,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)

int N;
i64 P;
vector<i64> H;
int main(){
  cin >> N >> P;
  H.resize(N);
  rep(i,0,N - 1) cin >> H[i];
  vector<i64> dp(N + 10,1LL << 60);
  int from = 0;
  dp[0] = 0;
  for(int i = 1;i < N;i++){
    dp[i] = dp[i - 1] + min(P,max(0LL,H[i] - H[i - 1]));
    if(H[i] - H[i - 1] >= 0){
    }
    else{
      dp[i] = min(dp[i] , dp[from] + P + (i == N - 1 ? 0LL : P));
      from = i;
    }
  }
  if(from != N - 1){
      dp[N - 1] = min(dp[N - 1] , dp[from] + P + (N - 1 == N - 1 ? 0LL : P));
  }
  cout << dp[N - 1] << endl;
}
0