結果
問題 |
No.595 登山
|
ユーザー |
![]() |
提出日時 | 2017-11-11 12:34:43 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 79 ms / 1,500 ms |
コード長 | 1,029 bytes |
コンパイル時間 | 1,347 ms |
コンパイル使用メモリ | 171,096 KB |
実行使用メモリ | 8,196 KB |
最終ジャッジ日時 | 2024-11-24 18:57:00 |
合計ジャッジ時間 | 3,497 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 25 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define REP(i,a,n) for(int i=(a); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it) #define ALLOF(c) (c).begin(), (c).end() typedef long long ll; typedef unsigned long long ull; #define INF 9222222222222222222LL ll dp[200005][2]; int main(){ int N; ll P; vector<ll> H; cin >> N >> P; rep(i,N){ ll a; cin >> a; H.push_back(a); } rep(i,200005){ dp[i][0] = INF; dp[i][1] = INF; } dp[0][0] = 0; REP(i,1,N){ //i-1 i // -> & -> dp[i][0] = min(dp[i][0], dp[i-1][0] + max(0LL,H[i]-H[i-1])); dp[i][0] = min(dp[i][0], dp[i-1][0] + P); // -> & <- dp[i][1] = min(dp[i][1], dp[i-1][0] + P); // <- & -> dp[i][0] = min(dp[i][0], dp[i-1][1] + P); // <- & <- dp[i][1] = min(dp[i][1], dp[i-1][1] + max(0LL,H[i-1]-H[i])); dp[i][1] = min(dp[i][1], dp[i-1][1] + P); } cout << min(dp[N-1][0], dp[N-1][1]) << endl; return 0; }