結果

問題 No.409 ダイエット
ユーザー fumofumofuni
提出日時 2021-10-29 13:37:27
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
RE  
実行時間 -
コード長 2,460 bytes
コンパイル時間 9,606 ms
コンパイル使用メモリ 270,516 KB
最終ジャッジ日時 2025-01-25 08:11:33
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 74 RE * 18
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=(n)-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=2e9+1;
const ll INF=4e18;
const ll dy[8]={-1,0,1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template <typename T> inline bool chmax(T &a, T b) {
return ((a < b) ? (a = b, true) : (false));
}
template <typename T> inline bool chmin(T &a, T b) {
return ((a > b) ? (a = b, true) : (false));
}
template<class T,typename Compare=less<T>>
struct monotone_minima{
int H;
vector<pair<int,T>> ans;
function<T(T,T)> f;
Compare comp;
monotone_minima(int _H,const function<T(T,T)> &_f,const Compare &_comp=Compare()){
H=_H,f=_f,comp=_comp;
ans.resize(H);
}
void calc(int top,int bottom,int left,int right){//
if(top>bottom)return;
int line=(top+bottom)/2;
T val=f(line,left);
int idx=left;
for(int i=left;i<=right;i++){
T nowval=f(line,i);
if(comp(nowval,val)){
val=nowval;
idx=i;
}
}
ans[line]=make_pair(idx,val);
calc(top,line-1,left,idx);
calc(line+1,bottom,idx,right);
}
};
ll n,a,b,w;
vl d,dp,fin;
auto fx=[](ll i,ll j){
ll len=i-j-1;
return dp[j]-a*len+len*(len+1)/2*b;
};
monotone_minima<ll> mm(200010,fx);
void induce(ll l,ll m,ll r){
for(int i=l;i<m;i++){//NlogN
if(!fin[i]){
dp[i]+=d[i];//d1
fin[i]=1;
}
}
mm.calc(m,r-1,l,m-1);//
for(int i=m;i<r;i++){
chmin(dp[i],mm.ans[i].second);
}
}
void solve(ll l,ll r){
if(l+1==r)return;
ll m=(l+r)/2;
solve(l,m);
induce(l,m,r);
solve(m,r);
}
int main(){
cin >> n >> a >> b >> w;
d.resize(n+2);dp.resize(n+2,INF);fin.resize(n+2);
dp[0]=w;
rep(i,n)cin >> d[i+1];//dp[n+1]
solve(0,n+2);
cout << dp.back() << endl;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0