結果

問題 No.409 ダイエット
ユーザー ttkkggwwttkkggww
提出日時 2023-02-11 19:22:50
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,899 bytes
コンパイル時間 5,071 ms
コンパイル使用メモリ 265,236 KB
実行使用メモリ 8,168 KB
最終ジャッジ日時 2023-09-22 15:15:57
合計ジャッジ時間 10,847 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 2 ms
4,376 KB
testcase_44 AC 3 ms
4,376 KB
testcase_45 AC 2 ms
4,380 KB
testcase_46 AC 2 ms
4,376 KB
testcase_47 AC 2 ms
4,376 KB
testcase_48 AC 2 ms
4,376 KB
testcase_49 AC 2 ms
4,376 KB
testcase_50 AC 2 ms
4,376 KB
testcase_51 AC 2 ms
4,380 KB
testcase_52 AC 2 ms
4,380 KB
testcase_53 AC 2 ms
4,376 KB
testcase_54 AC 2 ms
4,380 KB
testcase_55 WA -
testcase_56 AC 26 ms
7,640 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 WA -
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 AC 6 ms
4,380 KB
testcase_86 WA -
testcase_87 WA -
testcase_88 WA -
testcase_89 WA -
testcase_90 WA -
testcase_91 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#include<atcoder/all>
using namespace atcoder;
using ll = long long;
ll n,A,B,w;
vector<ll> d;
/**
 * @brief Convex Hull Trick Add Monotone
 * @docs docs/convex-hull-trick-add-monotone.md
*/
template< typename T, bool isMin >
struct ConvexHullTrickAddMonotone {/*{{{*/
#define F first
#define S second
	using P = pair< T, T >;
	deque< P > H;

	ConvexHullTrickAddMonotone() = default;

	bool empty() const { return H.empty(); }

	void clear() { H.clear(); }

	inline int sgn(T x) { return x == 0 ? 0 : (x < 0 ? -1 : 1); }

	inline bool check(const P &a, const P &b, const P &c) {
		if(b.S == a.S || c.S == b.S)
			return sgn(b.F - a.F) * sgn(c.S - b.S) >= sgn(c.F - b.F) * sgn(b.S - a.S);
		//return (b.F-a.F)*(c.S-b.S) >= (b.S-a.S)*(c.F-b.F);
		if(is_integral< T >::value) {
			return (b.S - a.S) / (a.F - b.F) >= (c.S - b.S) / (b.F - c.F);
		} else {
			return
				(b.F - a.F) * sgn(c.S - b.S) / abs(b.S - a.S) >=
				(c.F - b.F) * sgn(b.S - a.S) / abs(c.S - b.S);
		}
	}

	void add(T a, T b) {
		if(!isMin) a *= -1, b *= -1;
		P line(a, b);
		if(empty()) {
			H.emplace_front(line);
			return;
		}
		if(H.front().F <= a) {
			if(H.front().F == a) {
				if(H.front().S <= b) return;
				H.pop_front();
			}
			while(H.size() >= 2 && check(line, H.front(), H[1])) H.pop_front();
			H.emplace_front(line);
		} else {
			assert(a <= H.back().F);
			if(H.back().F == a) {
				if(H.back().S <= b) return;
				H.pop_back();
			}
			while(H.size() >= 2 && check(H[H.size() - 2], H.back(), line)) H.pop_back();
			H.emplace_back(line);
		}
	}

	inline T get_y(const P &a, const T &x) {
		return a.F * x + a.S;
	}

	T query(T x) {
		assert(!empty());
		int l = -1, r = H.size() - 1;
		while(l + 1 < r) {
			int m = (l + r) >> 1;
			if(get_y(H[m], x) >= get_y(H[m + 1], x)) l = m;
			else r = m;
		}
		if(isMin) return get_y(H[r], x);
		return -get_y(H[r], x);
	}

	T query_monotone_inc(T x) {
		assert(!empty());
		while(H.size() >= 2 && get_y(H.front(), x) >= get_y(H[1], x)) H.pop_front();
		if(isMin) return get_y(H.front(), x);
		return -get_y(H.front(), x);
	}

	T query_monotone_dec(T x) {
		assert(!empty());
		while(H.size() >= 2 && get_y(H.back(), x) >= get_y(H[H.size() - 2], x)) H.pop_back();
		if(isMin) return get_y(H.back(), x);
		return -get_y(H.back(), x);
	}

#undef F
#undef S
};/*}}}*/
void solve(){
	vector<ll> dp(n+1,INT_MAX);
	ConvexHullTrickAddMonotone<ll,true> cht;
		dp[0] = w;
	for(int i = 0;i<=n;i++){
		//if(i==1)continue;
		if(i){
			i--;
			ll x = (i*i+i)/2*B-A*i;
			ll cur = cht.query(i)+x;
			i++;
			//if(i==1)cout<<x<<endl;
			dp[i] = cur+d[i-1];
		}
		cht.add(-B*i,dp[i]+(i*i-i)/2*B+A*i);
		//cout<<cht.query(1)<<endl;
	}
	ll x = (n*n+n)/2*B-A*n;
	cout<<cht.query(n)+x<<endl;
}

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cin >> n >> A >> B >> w;
	d = vector<ll>(n);
	for(auto &i:d)cin >> i;
	solve();
}
0