結果

問題 No.595 登山
ユーザー takamoto_utakamoto_u
提出日時 2017-11-12 16:20:20
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,619 bytes
コンパイル時間 1,302 ms
コンパイル使用メモリ 149,500 KB
実行使用メモリ 11,192 KB
最終ジャッジ日時 2023-08-16 10:57:08
合計ジャッジ時間 3,693 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 15 ms
6,988 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 35 ms
11,024 KB
testcase_27 AC 27 ms
11,020 KB
testcase_28 AC 27 ms
10,988 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using u32 = uint32_t;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define MAXC(c, x) (c = max(c, x))
#define MINC(c, x) (c = min(c, x))

#define REP(i,n) for(auto i = 0 * (n), i##_len = (n); i < i##_len; ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,n) for(ll i=s, i##_len=(ll)(n); i<i##_len; ++i)
#define TEN(x) ((ll)1e##x)
const ll mod = TEN(9) + 7;

const ll INF = 1e9;

int main() {
	#ifdef INPUT_FROM_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
	#endif
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(50);

	ll n, p; cin >> n >> p;
	vl h(n); REP(i, n) cin >> h[i];

	// dp[constraint][i] :
	//    constraint = 0 : 次は左に進む必要がある
	//               = 1 : 次は右に進む必要がある
	//               = 2 : 次はワープする必要がある
	vvl dp(3, vl(n, TEN(15)));
	dp[0][0] = 0;
	dp[1][0] = p;
	FOR(i, 1, n) {
		dp[0][i] = min({
			dp[0][i],
			dp[0][i - 1] + min(p, max(0ll, h[i] - h[i - 1])),
			dp[2][i - 1] + p
		});
		dp[1][i] = min({
			dp[1][i],
			dp[0][i - 1] + p,
			dp[2][i - 1] + 2 * p,
			dp[1][i - 1] + min(p, max(0ll, h[i - 1] - h[i]))
		});
		dp[2][i] = min(
			dp[2][i],
			dp[1][i - 1] + min(p, max(0ll, h[i] - h[i - 1])) + p
		);
	}

	cout << min({ dp[0][n - 1], dp[1][n - 1], dp[2][n - 1] }) << endl;

	return 0;
}
0