結果
問題 |
No.595 登山
|
ユーザー |
![]() |
提出日時 | 2017-11-11 00:39:15 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 80 ms / 1,500 ms |
コード長 | 739 bytes |
コンパイル時間 | 2,180 ms |
コンパイル使用メモリ | 73,404 KB |
実行使用メモリ | 7,936 KB |
最終ジャッジ日時 | 2024-11-24 16:12:03 |
合計ジャッジ時間 | 2,775 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 25 |
ソースコード
#include <iostream> #include <vector> #include <string> #include <cmath> #include <algorithm> #include <utility> #include <queue> #include <set> #include <map> using namespace std; typedef long long ll; typedef pair<int,int> PII; typedef vector<int> VI; typedef vector<VI> VVI; #define MP make_pair #define PB push_back #define inf 1000000007 ll dp1[200010],dp2[200010]; int main(){ int n; cin >> n; ll p; cin >> p; vector<ll> v(n); for(int i=0;i<n;i++){ cin >> v[i]; } dp1[0]=0; dp2[0]=p; for(int i=1;i<n;i++){ dp1[i] = min(dp1[i-1]+p,min(dp1[i-1]+max(v[i]-v[i-1],(ll)0),dp2[i-1]+p)); dp2[i] = min(dp2[i-1]+p,min(dp2[i-1]+max(v[i-1]-v[i],(ll)0),dp1[i-1]+p)); } cout << min(dp1[n-1],dp2[n-1]) << endl; return 0; }