結果
| 問題 | No.595 登山 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-11-23 15:42:41 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 85 ms / 1,500 ms |
| コード長 | 573 bytes |
| 記録 | |
| コンパイル時間 | 748 ms |
| コンパイル使用メモリ | 72,824 KB |
| 実行使用メモリ | 9,600 KB |
| 最終ジャッジ日時 | 2024-10-11 06:59:20 |
| 合計ジャッジ時間 | 3,418 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 25 |
ソースコード
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;
int main(){
int n;
ll p;
cin >> n >> p;
ll h[n];
for(int i = 0; i < n; i++) cin >> h[i];
vector<vector<ll>> dp(2, vector<ll>(n, 1ll<<60));
dp[0][0] = dp[1][0] = 0;
for(int i = 1; i < n; i++){
dp[0][i] = min(min(dp[0][i-1],dp[1][i-1])+p, i==1 ? 1ll<<60 : dp[0][i-1]+max(0ll, h[i-1]-h[i]));
dp[1][i] = min(min(dp[0][i-1],dp[1][i-1])+p, dp[1][i-1]+max(0ll, h[i]-h[i-1]));
}
cout << min(dp[0].back(), dp[1].back()) << endl;
return 0;
}