結果

問題 No.409 ダイエット
ユーザー pekempeypekempey
提出日時 2016-08-06 01:06:06
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 80 ms / 2,000 ms
コード長 1,275 bytes
コンパイル時間 1,433 ms
コンパイル使用メモリ 149,908 KB
実行使用メモリ 13,640 KB
最終ジャッジ日時 2023-09-08 16:55:26
合計ジャッジ時間 6,538 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 2 ms
4,384 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 1 ms
4,388 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 2 ms
4,384 KB
testcase_12 AC 1 ms
4,384 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,384 KB
testcase_16 AC 1 ms
4,384 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,384 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,388 KB
testcase_24 AC 2 ms
4,384 KB
testcase_25 AC 2 ms
4,384 KB
testcase_26 AC 1 ms
4,384 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1 ms
4,384 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,384 KB
testcase_33 AC 2 ms
4,384 KB
testcase_34 AC 2 ms
4,384 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 2 ms
4,384 KB
testcase_37 AC 2 ms
4,384 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 2 ms
4,384 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 2 ms
4,384 KB
testcase_42 AC 2 ms
4,380 KB
testcase_43 AC 2 ms
4,384 KB
testcase_44 AC 2 ms
4,380 KB
testcase_45 AC 2 ms
4,384 KB
testcase_46 AC 2 ms
4,380 KB
testcase_47 AC 2 ms
4,380 KB
testcase_48 AC 2 ms
4,380 KB
testcase_49 AC 2 ms
4,380 KB
testcase_50 AC 2 ms
4,384 KB
testcase_51 AC 3 ms
4,384 KB
testcase_52 AC 2 ms
4,380 KB
testcase_53 AC 2 ms
4,384 KB
testcase_54 AC 2 ms
4,380 KB
testcase_55 AC 35 ms
7,292 KB
testcase_56 AC 30 ms
7,640 KB
testcase_57 AC 72 ms
13,640 KB
testcase_58 AC 31 ms
7,184 KB
testcase_59 AC 44 ms
8,056 KB
testcase_60 AC 28 ms
6,900 KB
testcase_61 AC 63 ms
12,908 KB
testcase_62 AC 68 ms
11,860 KB
testcase_63 AC 63 ms
12,184 KB
testcase_64 AC 33 ms
7,368 KB
testcase_65 AC 63 ms
9,424 KB
testcase_66 AC 71 ms
13,240 KB
testcase_67 AC 55 ms
11,632 KB
testcase_68 AC 43 ms
7,888 KB
testcase_69 AC 62 ms
11,972 KB
testcase_70 AC 66 ms
12,184 KB
testcase_71 AC 36 ms
7,328 KB
testcase_72 AC 80 ms
12,860 KB
testcase_73 AC 72 ms
11,828 KB
testcase_74 AC 46 ms
10,072 KB
testcase_75 AC 74 ms
12,208 KB
testcase_76 AC 54 ms
11,220 KB
testcase_77 AC 33 ms
6,196 KB
testcase_78 AC 41 ms
10,140 KB
testcase_79 AC 32 ms
6,892 KB
testcase_80 AC 74 ms
11,676 KB
testcase_81 AC 73 ms
12,068 KB
testcase_82 AC 54 ms
11,100 KB
testcase_83 AC 58 ms
10,860 KB
testcase_84 AC 47 ms
7,832 KB
testcase_85 AC 6 ms
4,380 KB
testcase_86 AC 46 ms
7,860 KB
testcase_87 AC 66 ms
11,696 KB
testcase_88 AC 25 ms
5,604 KB
testcase_89 AC 49 ms
6,840 KB
testcase_90 AC 23 ms
5,112 KB
testcase_91 AC 52 ms
7,000 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

template<class T>
struct ConvexHullTrick {
	vector<pair<T, T>> ls;

	bool need(pair<T, T> l1, pair<T, T> l2, pair<T, T> l3) {
		return -(l2.second - l1.second) * (l3.first - l2.first) < -(l3.second - l2.second) * (l2.first - l1.first);
	}

	void add(T a, T b) {
		pair<T, T> l(-a, -b);
		while (ls.size() >= 2 && !need(ls[ls.size() - 2], ls[ls.size() - 1], l)) ls.pop_back();
		ls.emplace_back(l);
	}

	T f(int k, T x) {
		return ls[k].first * x + ls[k].second;
	}

	T maximum(T x) {
		int pass = ls.size() - 1, fail = -1;
		while (pass - fail > 1) {
			int mid = (pass + fail) / 2;
			(f(mid, x) >= f(mid + 1, x) ? pass : fail) = mid;
		}
		return f(pass, x);
	}
};

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]);

	ConvexHullTrick<long long> cht;
	vector<long long> dp(N + 1);

	for (long long i = 0; i < N; i++) {
		cht.add(-i * B, i * (i - 1) / 2 * B + A * i + dp[i]);
		dp[i + 1] = -cht.maximum(i) + i * (i + 1) / 2 * B - A * i + D[i];
	}

	long long ans = LLONG_MAX;
	for (long long i = 0; i <= N; i++) {
		long long cand = dp[i] + (N - i) * (N - i + 1) / 2 * B - A * (N - i);
		ans = min(ans, cand);
	}
	cout << W + ans << endl;
}
0