結果

問題 No.595 登山
ユーザー mtsdmtsd
提出日時 2017-11-11 00:39:15
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 87 ms / 1,500 ms
コード長 739 bytes
コンパイル時間 757 ms
コンパイル使用メモリ 73,788 KB
実行使用メモリ 7,936 KB
最終ジャッジ日時 2024-05-03 15:05:02
合計ジャッジ時間 3,114 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 62 ms
7,584 KB
testcase_05 AC 19 ms
5,376 KB
testcase_06 AC 53 ms
6,912 KB
testcase_07 AC 7 ms
5,376 KB
testcase_08 AC 10 ms
5,376 KB
testcase_09 AC 53 ms
6,940 KB
testcase_10 AC 37 ms
5,760 KB
testcase_11 AC 33 ms
5,760 KB
testcase_12 AC 6 ms
5,376 KB
testcase_13 AC 17 ms
5,376 KB
testcase_14 AC 39 ms
7,780 KB
testcase_15 AC 40 ms
7,808 KB
testcase_16 AC 41 ms
7,808 KB
testcase_17 AC 40 ms
7,808 KB
testcase_18 AC 39 ms
7,908 KB
testcase_19 AC 85 ms
7,912 KB
testcase_20 AC 85 ms
7,936 KB
testcase_21 AC 84 ms
7,936 KB
testcase_22 AC 84 ms
7,908 KB
testcase_23 AC 84 ms
7,908 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 87 ms
7,808 KB
testcase_27 AC 65 ms
7,936 KB
testcase_28 AC 65 ms
7,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0