結果
問題 |
No.595 登山
|
ユーザー |
![]() |
提出日時 | 2018-11-30 19:56:36 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 29 ms / 1,500 ms |
コード長 | 1,097 bytes |
コンパイル時間 | 853 ms |
コンパイル使用メモリ | 98,068 KB |
実行使用メモリ | 8,064 KB |
最終ジャッジ日時 | 2024-06-26 23:43:24 |
合計ジャッジ時間 | 3,125 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 25 |
ソースコード
#include <cmath> #include <iostream> #include <vector> #include <queue> #include <deque> #include <map> #include <set> #include <stack> #include <tuple> #include <bitset> #include <algorithm> #include <functional> #include <utility> #include <iomanip> #define int long long int #define rep(i, n) for(int i = 0; i < (n); ++i) #define ALL(x) (x).begin(), (x).end() #define SZ(x) ((int)(x).size()) #define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ) using namespace std; typedef pair<int, int> P; const int INF = 1e15; const int MOD = 1e9+7; const int BIAS = 500; signed main(){ ios::sync_with_stdio(false); cin.tie(0); int n, p; cin >> n >> p; vector<int> h(n); rep(i, n) cin >> h[i]; vector<int> dpL(n, INF), dpR(n, INF); dpL[0] = 0; rep(i, n - 1){ dpL[i+1] = min(dpL[i], dpR[i]) + p; dpL[i+1] = min(dpL[i+1], dpL[i] + max(0LL, h[i+1] - h[i])); dpR[i+1] = min(dpL[i], dpR[i]) + p; dpR[i+1] = min(dpR[i+1], dpR[i] + max(0LL, h[i] - h[i+1])); } cout << min(dpL[n-1], dpR[n-1]) << endl; return 0; }