結果

問題 No.595 登山
ユーザー oxyshoweroxyshower
提出日時 2019-03-03 15:20:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 30 ms / 1,500 ms
コード長 612 bytes
コンパイル時間 1,537 ms
コンパイル使用メモリ 166,580 KB
実行使用メモリ 7,856 KB
最終ジャッジ日時 2023-09-05 17:44:46
合計ジャッジ時間 3,477 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 24 ms
7,588 KB
testcase_05 AC 8 ms
4,400 KB
testcase_06 AC 21 ms
6,932 KB
testcase_07 AC 4 ms
4,376 KB
testcase_08 AC 5 ms
4,376 KB
testcase_09 AC 20 ms
6,932 KB
testcase_10 AC 15 ms
5,680 KB
testcase_11 AC 13 ms
5,356 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 7 ms
4,376 KB
testcase_14 AC 19 ms
7,732 KB
testcase_15 AC 19 ms
7,788 KB
testcase_16 AC 18 ms
7,828 KB
testcase_17 AC 19 ms
7,820 KB
testcase_18 AC 18 ms
7,856 KB
testcase_19 AC 29 ms
7,788 KB
testcase_20 AC 29 ms
7,736 KB
testcase_21 AC 29 ms
7,736 KB
testcase_22 AC 28 ms
7,760 KB
testcase_23 AC 29 ms
7,832 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 30 ms
7,788 KB
testcase_27 AC 23 ms
7,716 KB
testcase_28 AC 24 ms
7,724 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long

const int INF = 1 << 30;

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n,p; cin >> n >> p;
  vector<int> h(n);
  for(int i = 0; i < n; i++){
    cin >> h[i];
  }

  vector<int> dp1(n,INF); //右向きの遷移
  vector<int> dp2(n,INF); //左向きの遷移
  dp1[0] = 0;
  dp2[0] = INF;
  for(int i = 0; i < n-1; i++){
    dp1[i+1] = min(dp1[i]+max(0LL,h[i+1]-h[i]), min(dp1[i],dp2[i])+p);
    dp2[i+1] = min(dp2[i]+max(0LL,h[i]-h[i+1]), min(dp1[i],dp2[i])+p);
  }
  cout << min(dp1[n-1],dp2[n-1]) << endl;

  return 0;
}
0