結果

問題 No.595 登山
ユーザー e869120e869120
提出日時 2017-11-10 22:54:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 83 ms / 1,500 ms
コード長 811 bytes
コンパイル時間 653 ms
コンパイル使用メモリ 83,264 KB
実行使用メモリ 8,192 KB
最終ジャッジ日時 2024-05-03 13:05:18
合計ジャッジ時間 2,875 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
5,376 KB
testcase_04 AC 58 ms
7,808 KB
testcase_05 AC 19 ms
5,376 KB
testcase_06 AC 51 ms
7,328 KB
testcase_07 AC 7 ms
5,376 KB
testcase_08 AC 10 ms
5,376 KB
testcase_09 AC 51 ms
7,296 KB
testcase_10 AC 36 ms
6,016 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 38 ms
8,116 KB
testcase_15 AC 39 ms
8,136 KB
testcase_16 AC 39 ms
8,140 KB
testcase_17 AC 39 ms
8,064 KB
testcase_18 AC 39 ms
8,192 KB
testcase_19 AC 83 ms
8,064 KB
testcase_20 AC 82 ms
8,152 KB
testcase_21 AC 81 ms
8,060 KB
testcase_22 AC 83 ms
8,036 KB
testcase_23 AC 82 ms
8,192 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 83 ms
8,008 KB
testcase_27 AC 64 ms
8,032 KB
testcase_28 AC 62 ms
8,064 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<functional>
#include<map>
using namespace std;
long long dp[200009][2], n, p, a[200009];
int main() {
	cin >> n >> p;
	for (int i = 1; i <= n; i++)cin >> a[i];
	for (int i = 0; i <= n + 1; i++) { dp[i][0] = (1LL << 60); dp[i][1] = (1LL << 60); }
	dp[1][0] = 0;
	for (int i = 1; i < n; i++) {
		dp[i + 1][0] = min(dp[i + 1][0], dp[i][0] + p);
		dp[i + 1][1] = min(dp[i + 1][1], dp[i][0] + p);
		dp[i + 1][0] = min(dp[i + 1][0], dp[i][1] + p);
		dp[i + 1][1] = min(dp[i + 1][1], dp[i][1] + p);
		dp[i + 1][0] = min(dp[i + 1][0], dp[i][0] + max(0LL, a[i + 1] - a[i]));
		dp[i + 1][1] = min(dp[i + 1][1], dp[i][1] + max(0LL, a[i] - a[i + 1]));
	}
	cout << min(dp[n][0], dp[n][1]) << endl;
	return 0;
}
0