結果

問題 No.409 ダイエット
ユーザー 🐬hec🐬hec
提出日時 2016-08-09 15:21:47
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 92 ms / 2,000 ms
コード長 1,688 bytes
コンパイル時間 1,612 ms
コンパイル使用メモリ 170,972 KB
実行使用メモリ 12,820 KB
最終ジャッジ日時 2023-09-08 16:59:46
合計ジャッジ時間 7,030 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
9,796 KB
testcase_01 AC 3 ms
9,576 KB
testcase_02 AC 3 ms
9,516 KB
testcase_03 AC 3 ms
9,472 KB
testcase_04 AC 3 ms
9,512 KB
testcase_05 AC 3 ms
9,504 KB
testcase_06 AC 2 ms
9,576 KB
testcase_07 AC 3 ms
9,496 KB
testcase_08 AC 3 ms
9,544 KB
testcase_09 AC 3 ms
9,484 KB
testcase_10 AC 3 ms
9,776 KB
testcase_11 AC 3 ms
9,468 KB
testcase_12 AC 3 ms
9,552 KB
testcase_13 AC 3 ms
9,544 KB
testcase_14 AC 3 ms
9,632 KB
testcase_15 AC 3 ms
9,704 KB
testcase_16 AC 3 ms
9,484 KB
testcase_17 AC 3 ms
9,608 KB
testcase_18 AC 3 ms
9,572 KB
testcase_19 AC 3 ms
9,544 KB
testcase_20 AC 3 ms
9,572 KB
testcase_21 AC 3 ms
9,676 KB
testcase_22 AC 3 ms
9,516 KB
testcase_23 AC 3 ms
9,472 KB
testcase_24 AC 3 ms
9,548 KB
testcase_25 AC 3 ms
9,472 KB
testcase_26 AC 3 ms
9,608 KB
testcase_27 AC 3 ms
9,572 KB
testcase_28 AC 3 ms
9,836 KB
testcase_29 AC 3 ms
9,564 KB
testcase_30 AC 3 ms
9,608 KB
testcase_31 AC 3 ms
9,768 KB
testcase_32 AC 3 ms
9,476 KB
testcase_33 AC 3 ms
9,524 KB
testcase_34 AC 2 ms
9,500 KB
testcase_35 AC 4 ms
9,508 KB
testcase_36 AC 4 ms
9,548 KB
testcase_37 AC 3 ms
9,504 KB
testcase_38 AC 4 ms
9,552 KB
testcase_39 AC 4 ms
9,488 KB
testcase_40 AC 4 ms
9,536 KB
testcase_41 AC 3 ms
9,540 KB
testcase_42 AC 4 ms
9,564 KB
testcase_43 AC 4 ms
9,568 KB
testcase_44 AC 3 ms
9,652 KB
testcase_45 AC 3 ms
9,596 KB
testcase_46 AC 3 ms
9,560 KB
testcase_47 AC 4 ms
9,632 KB
testcase_48 AC 3 ms
9,820 KB
testcase_49 AC 4 ms
9,492 KB
testcase_50 AC 4 ms
9,628 KB
testcase_51 AC 3 ms
9,552 KB
testcase_52 AC 4 ms
9,492 KB
testcase_53 AC 4 ms
9,732 KB
testcase_54 AC 3 ms
9,836 KB
testcase_55 AC 30 ms
10,580 KB
testcase_56 AC 56 ms
12,552 KB
testcase_57 AC 59 ms
12,684 KB
testcase_58 AC 26 ms
10,576 KB
testcase_59 AC 38 ms
11,136 KB
testcase_60 AC 24 ms
10,412 KB
testcase_61 AC 53 ms
12,448 KB
testcase_62 AC 55 ms
12,572 KB
testcase_63 AC 52 ms
12,292 KB
testcase_64 AC 28 ms
10,876 KB
testcase_65 AC 56 ms
12,520 KB
testcase_66 AC 59 ms
12,680 KB
testcase_67 AC 44 ms
11,724 KB
testcase_68 AC 37 ms
11,108 KB
testcase_69 AC 52 ms
12,236 KB
testcase_70 AC 77 ms
11,988 KB
testcase_71 AC 44 ms
10,620 KB
testcase_72 AC 92 ms
12,820 KB
testcase_73 AC 87 ms
12,496 KB
testcase_74 AC 54 ms
10,880 KB
testcase_75 AC 87 ms
12,528 KB
testcase_76 AC 62 ms
11,380 KB
testcase_77 AC 43 ms
10,528 KB
testcase_78 AC 47 ms
10,732 KB
testcase_79 AC 39 ms
10,412 KB
testcase_80 AC 87 ms
12,540 KB
testcase_81 AC 84 ms
12,412 KB
testcase_82 AC 64 ms
11,420 KB
testcase_83 AC 69 ms
11,712 KB
testcase_84 AC 57 ms
11,028 KB
testcase_85 AC 9 ms
9,708 KB
testcase_86 AC 55 ms
10,912 KB
testcase_87 AC 76 ms
12,008 KB
testcase_88 AC 33 ms
10,200 KB
testcase_89 AC 65 ms
11,524 KB
testcase_90 AC 31 ms
10,216 KB
testcase_91 AC 70 ms
11,660 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using namespace std;
using ll=long long;
const ll inf=1LL<<58;

ll d[300010];
ll ca[300010],cb[300010];
ll dp[300010];

deque<int> deq;

inline bool check(int i,int j,int k){ return (ca[j]-ca[i])*(cb[k]-cb[j])>= (cb[j]-cb[i])*(ca[k]-ca[j]);}
inline ll f(int idx,ll i){ return ca[idx]*i+cb[idx];}

int main(void){
	ll n,a,b,w;
	cin >> n >> a >> b >> w;
	rep(i,n) cin >> d[i];

	dp[0]=w,ca[0]=0,cb[0]=dp[0];
	deq.push_back(0);

	rep(i,1,n+1){
		while(deq.size()>=2 && f(deq[0],i) >= f(deq[1],i)) deq.pop_front();
		dp[i]=d[i-1]-1LL*(i-1)*a+1LL*(i-1)*i/2*b+f(deq[0],i);		
		ca[i]=-1LL*b*i,cb[i]=dp[i]+1LL*i*a+1LL*i*(i+1)/2*b;
		while(deq.size()>=2 && check(deq[int(deq.size())-2],deq[int(deq.size())-1],i)) deq.pop_back();
		deq.push_back(i);
	}

	ll ans=inf;
	rep(i,n+1){
	    ll e=n-i;
        chmin(ans,dp[i]-a*e+b*e*(e+1)/2);
    }
    cout << ans << endl;
	return 0;
}
0