結果

問題 No.409 ダイエット
ユーザー akusyounin2412akusyounin2412
提出日時 2019-02-03 22:56:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 142 ms / 2,000 ms
コード長 4,211 bytes
コンパイル時間 1,683 ms
コンパイル使用メモリ 132,748 KB
実行使用メモリ 17,060 KB
最終ジャッジ日時 2023-08-24 13:44:42
合計ジャッジ時間 8,698 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
9,488 KB
testcase_01 AC 3 ms
9,464 KB
testcase_02 AC 2 ms
9,528 KB
testcase_03 AC 3 ms
9,524 KB
testcase_04 AC 3 ms
9,452 KB
testcase_05 AC 2 ms
9,588 KB
testcase_06 AC 3 ms
9,528 KB
testcase_07 AC 2 ms
9,524 KB
testcase_08 AC 3 ms
9,472 KB
testcase_09 AC 3 ms
9,480 KB
testcase_10 AC 3 ms
9,580 KB
testcase_11 AC 3 ms
9,476 KB
testcase_12 AC 2 ms
9,580 KB
testcase_13 AC 3 ms
9,520 KB
testcase_14 AC 2 ms
9,452 KB
testcase_15 AC 3 ms
9,440 KB
testcase_16 AC 3 ms
9,616 KB
testcase_17 AC 3 ms
9,636 KB
testcase_18 AC 3 ms
9,520 KB
testcase_19 AC 2 ms
9,520 KB
testcase_20 AC 2 ms
9,584 KB
testcase_21 AC 3 ms
9,436 KB
testcase_22 AC 2 ms
9,520 KB
testcase_23 AC 3 ms
9,516 KB
testcase_24 AC 3 ms
9,520 KB
testcase_25 AC 2 ms
9,732 KB
testcase_26 AC 3 ms
9,532 KB
testcase_27 AC 3 ms
9,512 KB
testcase_28 AC 3 ms
9,452 KB
testcase_29 AC 3 ms
9,488 KB
testcase_30 AC 3 ms
9,532 KB
testcase_31 AC 3 ms
9,520 KB
testcase_32 AC 3 ms
9,512 KB
testcase_33 AC 2 ms
9,480 KB
testcase_34 AC 2 ms
9,468 KB
testcase_35 AC 4 ms
11,632 KB
testcase_36 AC 4 ms
11,648 KB
testcase_37 AC 4 ms
11,616 KB
testcase_38 AC 4 ms
11,664 KB
testcase_39 AC 5 ms
11,556 KB
testcase_40 AC 4 ms
11,596 KB
testcase_41 AC 4 ms
11,680 KB
testcase_42 AC 4 ms
11,588 KB
testcase_43 AC 4 ms
11,688 KB
testcase_44 AC 4 ms
11,668 KB
testcase_45 AC 4 ms
11,648 KB
testcase_46 AC 5 ms
11,588 KB
testcase_47 AC 4 ms
11,680 KB
testcase_48 AC 4 ms
11,628 KB
testcase_49 AC 4 ms
11,736 KB
testcase_50 AC 4 ms
11,600 KB
testcase_51 AC 4 ms
11,632 KB
testcase_52 AC 5 ms
11,604 KB
testcase_53 AC 4 ms
11,656 KB
testcase_54 AC 4 ms
11,808 KB
testcase_55 AC 53 ms
13,404 KB
testcase_56 AC 55 ms
12,212 KB
testcase_57 AC 108 ms
16,620 KB
testcase_58 AC 46 ms
13,408 KB
testcase_59 AC 66 ms
13,332 KB
testcase_60 AC 42 ms
13,404 KB
testcase_61 AC 96 ms
15,972 KB
testcase_62 AC 101 ms
16,300 KB
testcase_63 AC 94 ms
16,428 KB
testcase_64 AC 50 ms
13,228 KB
testcase_65 AC 96 ms
13,464 KB
testcase_66 AC 107 ms
17,024 KB
testcase_67 AC 81 ms
15,940 KB
testcase_68 AC 65 ms
13,312 KB
testcase_69 AC 93 ms
16,160 KB
testcase_70 AC 115 ms
16,092 KB
testcase_71 AC 64 ms
13,324 KB
testcase_72 AC 142 ms
16,900 KB
testcase_73 AC 129 ms
16,696 KB
testcase_74 AC 81 ms
15,572 KB
testcase_75 AC 130 ms
15,972 KB
testcase_76 AC 94 ms
15,520 KB
testcase_77 AC 61 ms
12,236 KB
testcase_78 AC 73 ms
16,472 KB
testcase_79 AC 57 ms
13,268 KB
testcase_80 AC 133 ms
16,488 KB
testcase_81 AC 129 ms
16,172 KB
testcase_82 AC 96 ms
15,888 KB
testcase_83 AC 104 ms
17,060 KB
testcase_84 AC 82 ms
13,264 KB
testcase_85 AC 12 ms
11,684 KB
testcase_86 AC 81 ms
13,448 KB
testcase_87 AC 116 ms
15,968 KB
testcase_88 AC 48 ms
12,368 KB
testcase_89 AC 91 ms
12,004 KB
testcase_90 AC 42 ms
11,776 KB
testcase_91 AC 96 ms
11,960 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7; //924844033 1000000000 + 9;
constexpr long long INF = numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<double, double> Dll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourth; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, t, s, p, q, last, first, cnt, sum, ans, dp[330000],a[330020], b[330000];
string str, ss;
bool f[220000];
char c[4000][4000];
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
struct Edge { LL to, cost; };
struct edge {
	LL from, to, cost;
};
vector<vector<Edge>>vec,rvec;
vector<edge>ed;
vector<LL>v;
map<string, LL>ma;
set<LL>st;

void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
template<typename T>
class ConvecHullTrick {
private:
	// 直線群(配列)
	std::vector<std::pair<T, T>> lines;
	// 最小値(最大値)を求めるxが単調であるか
	bool isMonotonicX;
	// 最小/最大を判断する関数
	std::function<bool(T l, T r)> comp;

public:
	// コンストラクタ ( クエリが単調であった場合はflag = trueとする )
	ConvecHullTrick(bool flagX = false, std::function<bool(T l, T r)> compFunc = [](T l, T r) {return l >= r; })
		:isMonotonicX(flagX), comp(compFunc) {
		lines.emplace_back(0, 0);
	};

	// 直線l1, l2, l3のうちl2が不必要であるかどうか
	bool check(std::pair<T, T> l1, std::pair<T, T> l2, std::pair<T, T> l3) {
		if (l1 < l3) std::swap(l1, l3);
		return (l3.second - l2.second) * (l2.first - l1.first) >= (l2.second - l1.second) * (l3.first - l2.first);
	}

	// 直線y=ax+bを追加する
	void add(T a, T b) {
		std::pair<T, T> line(a, b);
		while (lines.size() >= 2 && check(*(lines.end() - 2), lines.back(), line))
			lines.pop_back();
		lines.emplace_back(line);
	}

	// i番目の直線f_i(x)に対するxの時の値を返す
	T f(int i, T x) {
		return lines[i].first * x + lines[i].second;
	}

	// i番目の直線f_i(x)に対するxの時の値を返す
	T f(std::pair<T, T> line, T x) {
		return line.first * x + line.second;
	}

	// 直線群の中でxの時に最小(最大)となる値を返す
	T get(T x) {
		// 最小値(最大値)クエリにおけるxが単調
		if (isMonotonicX) {
			static int head = 0;
			while (lines.size() - head >= 2 && comp(f(head, x), f(head + 1, x)))
				++head;
			return f(head, x);
		}
		else {
			int low = -1, high = lines.size() - 1;
			while (high - low > 1) {
				int mid = (high + low) / 2;
				(comp(f(mid, x), f(mid + 1, x)) ? low : high) = mid;
			}
			return f(high, x);
		}
	}
};
ConvecHullTrick<LL> cht;
int main() {
	LL A, B;
	cin >> n >> A >> B >> s;
	rep(i, n) {
		cin >> a[i];
	}
	dp[0] = 0;
	cht.add(0, 0);
	for (LL i = 1; i < n + 1; i++) {
		dp[i] = a[i - 1] - A * (i - 1) + B * i * (i - 1LL) / 2 + cht.get(i);
		cht.add(-B * i, dp[i] + i * A + B * i * (i + 1LL) / 2);
	}
	ans = INF;
	rep(i, n + 1) {
		ans = min(ans, s+dp[i] - (n - i)*A + B * (n - i)*(n - i + 1) / 2);
	}
	cout << ans << endl;
	return 0;
}
0