結果

問題 No.409 ダイエット
コンテスト
ユーザー pekempey
提出日時 2016-08-05 23:12:09
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 447 ms / 2,000 ms
コード長 707 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,469 ms
コンパイル使用メモリ 177,404 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2026-03-13 02:14:26
合計ジャッジ時間 14,221 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 92
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

const long long inf = 1e16;

template<class T1, class T2>
void chmin(T1 &a, T2 b) {
	if (b < a) a = b;
}

int main() {
	long long N, A, B, W;
	cin >> N >> A >> B >> W;
	vector<long long> D(N);
	for (int i = 0; i < N; i++) scanf("%lld", &D[i]);

	if (B == 0) {
		cout << W - N * A << endl;
		return 0;
	}

	static long long dp0[1010], dp1[1010];
	fill_n(dp0, 1010, inf);
	dp0[0] = 0;

	for (int i = 0; i < N; i++) {
		fill_n(dp1, 1010, inf);
		for (int j = 0; j < 1007; j++) {
			chmin(dp1[0], dp0[j] + D[i]);
			chmin(dp1[j + 1], dp0[j] + B * (j + 1) - A);
		}
		swap(dp0, dp1);
	}

	long long mini = *min_element(dp0, dp0 + 1010);
	cout << W + mini << endl;
}
0