結果

問題 No.595 登山
ユーザー Mr.SpockMr.Spock
提出日時 2021-02-19 17:07:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 31 ms / 1,500 ms
コード長 576 bytes
コンパイル時間 1,471 ms
コンパイル使用メモリ 167,884 KB
実行使用メモリ 7,880 KB
最終ジャッジ日時 2023-10-14 11:01:50
合計ジャッジ時間 3,782 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 24 ms
7,368 KB
testcase_05 AC 8 ms
4,368 KB
testcase_06 AC 21 ms
6,956 KB
testcase_07 AC 4 ms
4,352 KB
testcase_08 AC 4 ms
4,352 KB
testcase_09 AC 21 ms
6,880 KB
testcase_10 AC 15 ms
5,540 KB
testcase_11 AC 13 ms
5,388 KB
testcase_12 AC 3 ms
4,352 KB
testcase_13 AC 7 ms
4,352 KB
testcase_14 AC 19 ms
7,616 KB
testcase_15 AC 18 ms
7,748 KB
testcase_16 AC 19 ms
7,732 KB
testcase_17 AC 18 ms
7,764 KB
testcase_18 AC 19 ms
7,816 KB
testcase_19 AC 29 ms
7,756 KB
testcase_20 AC 29 ms
7,680 KB
testcase_21 AC 29 ms
7,616 KB
testcase_22 AC 30 ms
7,672 KB
testcase_23 AC 29 ms
7,632 KB
testcase_24 AC 2 ms
4,352 KB
testcase_25 AC 1 ms
4,352 KB
testcase_26 AC 31 ms
7,764 KB
testcase_27 AC 24 ms
7,776 KB
testcase_28 AC 24 ms
7,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n, k;
	cin >> n >> k;
	vector<ll>x(n);
	for (ll i = 0; i < n; i++) {
		cin >> x[i];
	}
	vector<ll>dpl(n, 1e9), dpr(n, 1e9);
	dpl[0] = 0;
	for (ll i = 0; i < n - 1; i++) {
		dpl[i + 1] = min(dpl[i], dpr[i]) + k;
		dpl[i + 1] = min(dpl[i + 1], dpl[i] + max(0ll, (x[i + 1] - x[i])));
		dpr[i + 1] = min(dpr[i], dpl[i]) + k;
		dpr[i + 1] = min(dpr[i + 1], dpr[i] + max(0ll, (x[i] - x[i + 1])));
	}
	cout << min(dpl[n - 1], dpr[n - 1]) << endl;
}
0