結果

問題 No.409 ダイエット
ユーザー pekempeypekempey
提出日時 2016-08-06 00:17:06
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,288 bytes
コンパイル時間 1,157 ms
コンパイル使用メモリ 164,192 KB
実行使用メモリ 12,092 KB
最終ジャッジ日時 2024-04-24 15:39:12
合計ジャッジ時間 5,199 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 WA -
testcase_07 AC 1 ms
5,376 KB
testcase_08 WA -
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 WA -
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
testcase_25 WA -
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 1 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 1 ms
5,376 KB
testcase_32 WA -
testcase_33 AC 1 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 AC 31 ms
7,552 KB
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 WA -
testcase_63 WA -
testcase_64 WA -
testcase_65 AC 59 ms
9,568 KB
testcase_66 WA -
testcase_67 WA -
testcase_68 WA -
testcase_69 WA -
testcase_70 WA -
testcase_71 WA -
testcase_72 WA -
testcase_73 WA -
testcase_74 WA -
testcase_75 WA -
testcase_76 WA -
testcase_77 WA -
testcase_78 WA -
testcase_79 WA -
testcase_80 WA -
testcase_81 WA -
testcase_82 WA -
testcase_83 WA -
testcase_84 WA -
testcase_85 WA -
testcase_86 WA -
testcase_87 WA -
testcase_88 WA -
testcase_89 AC 43 ms
6,912 KB
testcase_90 AC 21 ms
5,376 KB
testcase_91 AC 47 ms
7,168 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:36:42: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   36 |         for (int i = 0; i < N; i++) scanf("%lld", &D[i]);
      |                                     ~~~~~^~~~~~~~~~~~~~~

ソースコード

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 minimum(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;
	cht.add(0, 0);
	vector<long long> dp(N + 1);

	for (long long i = 0; i < N; i++) {
		dp[i + 1] = cht.minimum(i) + i * (i + 1) / 2 * B - A * i + D[i];
		cht.add(-i * B, i * (i - 1) / 2 * B + A * i + dp[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