結果
問題 |
No.595 登山
|
ユーザー |
![]() |
提出日時 | 2019-08-13 06:09:30 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 31 ms / 1,500 ms |
コード長 | 882 bytes |
コンパイル時間 | 345 ms |
コンパイル使用メモリ | 52,300 KB |
実行使用メモリ | 7,680 KB |
最終ジャッジ日時 | 2024-09-19 06:59:39 |
合計ジャッジ時間 | 2,227 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 25 |
ソースコード
#include <cstdio> #include <vector> #include <algorithm> using namespace std; using ll = long long int; ll dp[200010][2]; const ll INF = 1LL << 60; int main() { ll N, P; scanf("%lld%lld", &N, &P); vector<ll> H(N); for(int i=0; i<N; i++) scanf("%lld", &H[i]); fill(dp[0], dp[N+1], INF); dp[0][0] = 0; for(int i=0; i+1<N; i++) { for(int x=0; x<2; x++) { // fprintf(stderr, "dp[%d][%d] = %lld\n", i+1, x, dp[i][x]); for(int y=0; y<2; y++) { ll add = P; if(x == y and y == 0) add = min(add, max(H[i+1] - H[i], 0LL)); if(x == y and y == 1) add = min(add, max(H[i] - H[i+1], 0LL)); dp[i+1][y] = min(dp[i+1][y], dp[i][x] + add); } } // fprintf(stderr, "\n"); } printf("%lld\n", min(dp[N-1][0], dp[N-1][1])); return 0; }