結果

問題 No.595 登山
ユーザー Naoyk1212Naoyk1212
提出日時 2017-11-11 01:39:28
言語 C++11
(gcc 11.4.0)
結果
MLE  
(最新)
AC  
(最初)
実行時間 -
コード長 794 bytes
コンパイル時間 969 ms
コンパイル使用メモリ 63,708 KB
実行使用メモリ 814,896 KB
最終ジャッジ日時 2023-08-16 06:09:25
合計ジャッジ時間 5,213 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘long long int to(long long int&, long long int)’:
main.cpp:12:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^

ソースコード

diff #

#include<iostream>
#include<vector>
#include<stack>
#include <algorithm>


long long dp[200001][2];
const long long inf = 1e18;

long long to(long long &x, long long y) {
	x = std::min(x, y);
}

int main(){
	int n, p;
	std::cin >> n >> p;
	
	std::vector<int> h(n);
	for (int i = 0; i < n; i++) {
		std::cin >> h[i];
	}

	std::fill_n(*dp, 200001 * 2, inf);
	dp[0][0] = 0;
	dp[0][1] = p;

	// 0: ->
	// 1: <-

	for (int i = 0; i + 1 < n; i++) {
		to(dp[i + 1][0], dp[i][0] + std::max(0, h[i + 1] - h[i]));
		to(dp[i + 1][0], dp[i][0] + p);
		to(dp[i + 1][1], dp[i][0] + p);
		to(dp[i + 1][0], dp[i][1] + p);
		to(dp[i + 1][1], dp[i][1] + std::max(0, h[i] - h[i + 1]));
		to(dp[i + 1][1], dp[i][1] + p);
	}

	long long ans = std::min(dp[n - 1][0], dp[n - 1][1]);
	std::cout << ans << std::endl;
}
0