結果

問題 No.409 ダイエット
ユーザー chocoruskchocorusk
提出日時 2020-01-01 14:47:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 94 ms / 2,000 ms
コード長 2,348 bytes
コンパイル時間 1,089 ms
コンパイル使用メモリ 117,120 KB
実行使用メモリ 5,788 KB
最終ジャッジ日時 2023-08-14 09:19:02
合計ジャッジ時間 8,814 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 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,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 3 ms
4,376 KB
testcase_38 AC 2 ms
4,384 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 3 ms
4,380 KB
testcase_41 AC 3 ms
4,380 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 2 ms
4,376 KB
testcase_44 AC 2 ms
4,380 KB
testcase_45 AC 2 ms
4,380 KB
testcase_46 AC 3 ms
4,376 KB
testcase_47 AC 2 ms
4,380 KB
testcase_48 AC 2 ms
4,380 KB
testcase_49 AC 3 ms
4,380 KB
testcase_50 AC 2 ms
4,376 KB
testcase_51 AC 3 ms
4,380 KB
testcase_52 AC 2 ms
4,380 KB
testcase_53 AC 3 ms
4,376 KB
testcase_54 AC 2 ms
4,376 KB
testcase_55 AC 31 ms
4,420 KB
testcase_56 AC 53 ms
5,524 KB
testcase_57 AC 61 ms
5,764 KB
testcase_58 AC 27 ms
4,384 KB
testcase_59 AC 38 ms
4,712 KB
testcase_60 AC 25 ms
4,384 KB
testcase_61 AC 55 ms
5,536 KB
testcase_62 AC 58 ms
5,452 KB
testcase_63 AC 54 ms
5,396 KB
testcase_64 AC 29 ms
4,468 KB
testcase_65 AC 58 ms
5,484 KB
testcase_66 AC 59 ms
5,692 KB
testcase_67 AC 46 ms
5,044 KB
testcase_68 AC 39 ms
4,672 KB
testcase_69 AC 54 ms
5,556 KB
testcase_70 AC 79 ms
5,196 KB
testcase_71 AC 44 ms
4,440 KB
testcase_72 AC 94 ms
5,780 KB
testcase_73 AC 89 ms
5,352 KB
testcase_74 AC 55 ms
4,824 KB
testcase_75 AC 88 ms
5,408 KB
testcase_76 AC 64 ms
4,856 KB
testcase_77 AC 43 ms
4,376 KB
testcase_78 AC 49 ms
4,520 KB
testcase_79 AC 39 ms
4,412 KB
testcase_80 AC 90 ms
5,788 KB
testcase_81 AC 88 ms
5,460 KB
testcase_82 AC 65 ms
4,804 KB
testcase_83 AC 70 ms
4,948 KB
testcase_84 AC 58 ms
4,748 KB
testcase_85 AC 8 ms
4,380 KB
testcase_86 AC 57 ms
4,832 KB
testcase_87 AC 78 ms
5,220 KB
testcase_88 AC 33 ms
4,380 KB
testcase_89 AC 68 ms
4,900 KB
testcase_90 AC 32 ms
4,376 KB
testcase_91 AC 73 ms
4,960 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef __int128_t lll;
template<typename T, bool ismin=true>
struct ConvexHullTrickMonotone{
	using P=pair<T, T>;
	deque<P> deq;
	ConvexHullTrickMonotone(){}
	void add(T a, T b){
		if(!ismin) a*=(-1), b*=(-1);
		if(deq.empty()){
			deq.push_back({a, b});
			return;
		}
		if(deq.back().first>=a){
			if(deq.back().first==a && deq.back().second<=b) return;
			while(deq.size()>1){
				T a1=deq.back().first, b1=deq.back().second;
				T a2=deq[deq.size()-2].first, b2=deq[deq.size()-2].second;
				if((b1-b2)*(a1-a)<(b-b1)*(a2-a1)) break;
				deq.pop_back();
			}
			deq.push_back({a, b});
		}else{
			while(deq.size()>1){
				T a1=deq.front().first, b1=deq.front().second;
				T a2=deq[1].first, b2=deq[1].second;
				if((b1-b2)*(a1-a)>(b-b1)*(a2-a1)) break;
				deq.pop_front();
			}
			deq.push_front({a, b});
		}
	}
	T get(T x, bool isinc){
		if(isinc){
			while(deq.size()>1){
				T a1=deq.front().first, b1=deq.front().second;
				T a2=deq[1].first, b2=deq[1].second;
				if(a1*x+b1<a2*x+b2) break;
				deq.pop_front();
			}
			T ret=deq.front().first*x+deq.front().second;
			if(ismin) return ret;
			else return -ret;
		}else{
			while(deq.size()>1){
				T a1=deq.back().first, b1=deq.back().second;
				T a2=deq[deq.size()-2].first, b2=deq[deq.size()-2].second;
				if(a1*x+b1<a2*x+b2) break;
				deq.pop_back();
			}
			T ret=deq.back().first*x+deq.back().second;
			if(ismin) return ret;
			else return -ret;
		}
	}
	void clear(){
		deq.clear();
	}
};
int main()
{
	int n;
	ll a, b, w;
	cin>>n>>a>>b>>w;
	ll d[300030]; d[n+1]=0;
	for(int i=1; i<=n; i++) cin>>d[i];
	ConvexHullTrickMonotone<lll> cht;
	cht.add(0, w);
	for(int i=1; i<=n+1; i++){
		ll dp=cht.get(i, true)+b*(i-1)*i/2+d[i]-a*(i-1);
		if(i==n+1){
			cout<<dp<<endl;
			return 0;
		}
		cht.add(-b*i, b*i*(i+1)/2+a*i+dp);
	}
 	return 0;
}
0