結果

問題 No.409 ダイエット
ユーザー fumofumofunifumofumofuni
提出日時 2021-10-29 12:24:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 255 ms / 2,000 ms
コード長 2,362 bytes
コンパイル時間 2,353 ms
コンパイル使用メモリ 203,948 KB
実行使用メモリ 12,972 KB
最終ジャッジ日時 2024-04-16 13:20:32
合計ジャッジ時間 11,926 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 1 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 AC 4 ms
5,376 KB
testcase_36 AC 3 ms
5,376 KB
testcase_37 AC 3 ms
5,376 KB
testcase_38 AC 4 ms
5,376 KB
testcase_39 AC 3 ms
5,376 KB
testcase_40 AC 4 ms
5,376 KB
testcase_41 AC 3 ms
5,376 KB
testcase_42 AC 4 ms
5,376 KB
testcase_43 AC 4 ms
5,376 KB
testcase_44 AC 4 ms
5,376 KB
testcase_45 AC 4 ms
5,376 KB
testcase_46 AC 4 ms
5,376 KB
testcase_47 AC 4 ms
5,376 KB
testcase_48 AC 3 ms
5,376 KB
testcase_49 AC 3 ms
5,376 KB
testcase_50 AC 3 ms
5,376 KB
testcase_51 AC 3 ms
5,376 KB
testcase_52 AC 3 ms
5,376 KB
testcase_53 AC 4 ms
5,376 KB
testcase_54 AC 3 ms
5,376 KB
testcase_55 AC 102 ms
7,988 KB
testcase_56 AC 237 ms
12,568 KB
testcase_57 AC 217 ms
12,948 KB
testcase_58 AC 87 ms
7,300 KB
testcase_59 AC 133 ms
9,132 KB
testcase_60 AC 76 ms
6,980 KB
testcase_61 AC 191 ms
11,688 KB
testcase_62 AC 209 ms
12,484 KB
testcase_63 AC 187 ms
11,604 KB
testcase_64 AC 99 ms
7,680 KB
testcase_65 AC 208 ms
12,004 KB
testcase_66 AC 220 ms
12,656 KB
testcase_67 AC 155 ms
10,452 KB
testcase_68 AC 128 ms
9,060 KB
testcase_69 AC 180 ms
11,344 KB
testcase_70 AC 204 ms
11,032 KB
testcase_71 AC 107 ms
7,468 KB
testcase_72 AC 255 ms
12,972 KB
testcase_73 AC 228 ms
11,836 KB
testcase_74 AC 140 ms
8,632 KB
testcase_75 AC 238 ms
11,992 KB
testcase_76 AC 164 ms
9,564 KB
testcase_77 AC 110 ms
7,372 KB
testcase_78 AC 127 ms
8,092 KB
testcase_79 AC 93 ms
7,116 KB
testcase_80 AC 241 ms
12,288 KB
testcase_81 AC 226 ms
11,796 KB
testcase_82 AC 164 ms
9,780 KB
testcase_83 AC 179 ms
10,148 KB
testcase_84 AC 146 ms
8,952 KB
testcase_85 AC 15 ms
5,376 KB
testcase_86 AC 145 ms
8,708 KB
testcase_87 AC 202 ms
11,052 KB
testcase_88 AC 76 ms
6,332 KB
testcase_89 AC 184 ms
9,724 KB
testcase_90 AC 79 ms
6,460 KB
testcase_91 AC 196 ms
10,176 KB
権限があれば一括ダウンロードができます

ソースコード

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<typename T,typename Compare=less<T>>
vector<pair<int,T>> monotone_minima(int H,int W,const function<T(int,int)> &f,const Compare &comp=Compare()){
    vector<pair<int,T>> dp(H);
    function<void(int,int,int,int)> dfs=[&](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;
            }
        }
        dp[line]=make_pair(idx,val);
        dfs(top,line-1,left,idx);
        dfs(line+1,bottom,idx,right);
    };
    dfs(0,H-1,0,W-1);
    return dp;
}

ll n,a,b,w;
vl dp,d,fin;
ll basej,basei;
auto fx=[](ll i,ll j){
  ll len=(basei+i)-(basej+j)-1;
  return dp[basej+j]-a*len+len*(len+1)/2*b;
};
void induce(ll l,ll m,ll r){
  basei=m;basej=l;
  for(int i=l;i<m;i++){
    if(!fin[i]){
      dp[i]+=d[i];
      fin[i]=1;
    }
  }
  auto ans=monotone_minima<ll>(r-m,m-l,fx);
  for(int i=m;i<r;i++){
    chmin(dp[i],ans[i-m].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];
  solve(0,n+2);
  cout << dp.back() << endl;
} 
0