結果

問題 No.409 ダイエット
ユーザー nxterunxteru
提出日時 2018-11-10 13:02:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 630 bytes
コンパイル時間 1,463 ms
コンパイル使用メモリ 166,100 KB
実行使用メモリ 12,960 KB
最終ジャッジ日時 2023-08-15 20:01:00
合計ジャッジ時間 6,039 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,764 KB
testcase_01 AC 2 ms
7,584 KB
testcase_02 AC 2 ms
7,616 KB
testcase_03 AC 2 ms
7,756 KB
testcase_04 AC 2 ms
7,552 KB
testcase_05 AC 3 ms
7,704 KB
testcase_06 AC 2 ms
7,564 KB
testcase_07 AC 2 ms
7,628 KB
testcase_08 AC 2 ms
7,612 KB
testcase_09 AC 2 ms
7,628 KB
testcase_10 AC 2 ms
7,672 KB
testcase_11 AC 2 ms
7,620 KB
testcase_12 AC 3 ms
7,864 KB
testcase_13 AC 2 ms
7,588 KB
testcase_14 AC 2 ms
7,620 KB
testcase_15 AC 2 ms
7,616 KB
testcase_16 AC 2 ms
7,568 KB
testcase_17 AC 3 ms
7,580 KB
testcase_18 AC 2 ms
7,624 KB
testcase_19 AC 3 ms
7,612 KB
testcase_20 AC 2 ms
7,760 KB
testcase_21 AC 2 ms
7,676 KB
testcase_22 AC 2 ms
7,620 KB
testcase_23 AC 2 ms
7,624 KB
testcase_24 AC 2 ms
7,844 KB
testcase_25 AC 2 ms
7,760 KB
testcase_26 AC 2 ms
7,568 KB
testcase_27 AC 2 ms
7,620 KB
testcase_28 AC 3 ms
7,564 KB
testcase_29 AC 2 ms
7,608 KB
testcase_30 AC 2 ms
7,760 KB
testcase_31 AC 3 ms
7,756 KB
testcase_32 AC 3 ms
7,864 KB
testcase_33 AC 3 ms
7,684 KB
testcase_34 AC 3 ms
7,656 KB
testcase_35 AC 3 ms
7,660 KB
testcase_36 AC 3 ms
7,576 KB
testcase_37 AC 3 ms
7,652 KB
testcase_38 AC 3 ms
7,660 KB
testcase_39 AC 3 ms
7,668 KB
testcase_40 AC 3 ms
7,884 KB
testcase_41 AC 3 ms
7,800 KB
testcase_42 AC 3 ms
7,900 KB
testcase_43 AC 3 ms
7,664 KB
testcase_44 AC 2 ms
7,660 KB
testcase_45 AC 3 ms
7,660 KB
testcase_46 AC 2 ms
7,880 KB
testcase_47 AC 2 ms
7,660 KB
testcase_48 AC 3 ms
7,684 KB
testcase_49 AC 3 ms
7,736 KB
testcase_50 AC 2 ms
7,644 KB
testcase_51 AC 2 ms
7,660 KB
testcase_52 AC 3 ms
7,660 KB
testcase_53 AC 3 ms
7,716 KB
testcase_54 AC 3 ms
7,720 KB
testcase_55 AC 16 ms
9,292 KB
testcase_56 AC 27 ms
8,608 KB
testcase_57 AC 31 ms
12,960 KB
testcase_58 AC 14 ms
9,452 KB
testcase_59 AC 20 ms
9,304 KB
testcase_60 AC 13 ms
9,064 KB
testcase_61 AC 28 ms
12,612 KB
testcase_62 AC 28 ms
12,612 KB
testcase_63 AC 27 ms
12,516 KB
testcase_64 AC 16 ms
9,236 KB
testcase_65 AC 29 ms
10,124 KB
testcase_66 AC 30 ms
12,912 KB
testcase_67 AC 24 ms
12,288 KB
testcase_68 AC 19 ms
9,356 KB
testcase_69 AC 27 ms
12,532 KB
testcase_70 AC 32 ms
12,392 KB
testcase_71 AC 19 ms
9,348 KB
testcase_72 AC 38 ms
12,748 KB
testcase_73 AC 37 ms
12,528 KB
testcase_74 AC 23 ms
11,836 KB
testcase_75 AC 37 ms
12,676 KB
testcase_76 AC 27 ms
12,024 KB
testcase_77 AC 18 ms
8,780 KB
testcase_78 AC 20 ms
11,776 KB
testcase_79 AC 17 ms
8,948 KB
testcase_80 AC 36 ms
12,796 KB
testcase_81 AC 37 ms
12,812 KB
testcase_82 AC 27 ms
12,056 KB
testcase_83 AC 30 ms
12,176 KB
testcase_84 AC 24 ms
9,068 KB
testcase_85 AC 5 ms
7,752 KB
testcase_86 AC 23 ms
9,100 KB
testcase_87 AC 32 ms
12,528 KB
testcase_88 AC 14 ms
8,436 KB
testcase_89 AC 27 ms
8,368 KB
testcase_90 AC 13 ms
7,952 KB
testcase_91 AC 29 ms
8,508 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define F first
#define S second
ll n,A,B,W,d[300005],dp[300005];
P dq[300005];
bool check(P a,P b,P c){return (a.F-b.F)*(b.S-c.S)>=(a.S-b.S)*(b.F-c.F);}
int main(void){
	scanf("%lld%lld%lld%lld",&n,&A,&B,&W);
	for(int i=1;i<=n;i++)scanf("%lld",d+i);
	dp[0]=W;
	ll l=0,r=0;
	for(ll i=1;i<=n+1;i++){
		P p=P(-B*i,dp[i-1]+B*i*(i-1)/2+i*A);
		while(r-2>=l&&check(dq[r-2],dq[r-1],p))r--;
		dq[r++]=p;
		while(l+1<r&&dq[l+1].F*i+dq[l+1].S<=dq[l].F*i+dq[l].S)l++;
		dp[i]=dq[l].F*i+dq[l].S+d[i]-A*i+B*i*(i+1)/2;
	}	
	printf("%lld\n",dp[n+1]);
}
0