結果
問題 |
No.595 登山
|
ユーザー |
![]() |
提出日時 | 2019-03-03 15:20:11 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 28 ms / 1,500 ms |
コード長 | 612 bytes |
コンパイル時間 | 1,575 ms |
コンパイル使用メモリ | 168,720 KB |
実行使用メモリ | 7,936 KB |
最終ジャッジ日時 | 2024-06-23 13:13:27 |
合計ジャッジ時間 | 3,554 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 25 |
ソースコード
#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; }