結果

問題 No.409 ダイエット
ユーザー fumofumofunifumofumofuni
提出日時 2021-10-29 13:37:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,460 bytes
コンパイル時間 2,508 ms
コンパイル使用メモリ 209,080 KB
実行使用メモリ 13,208 KB
最終ジャッジ日時 2024-04-16 13:21:29
合計ジャッジ時間 12,457 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,400 KB
testcase_01 AC 3 ms
6,400 KB
testcase_02 AC 5 ms
6,400 KB
testcase_03 AC 3 ms
6,528 KB
testcase_04 AC 4 ms
6,400 KB
testcase_05 AC 4 ms
6,528 KB
testcase_06 AC 3 ms
6,400 KB
testcase_07 AC 4 ms
6,528 KB
testcase_08 AC 3 ms
6,528 KB
testcase_09 AC 3 ms
6,528 KB
testcase_10 AC 4 ms
6,400 KB
testcase_11 AC 3 ms
6,528 KB
testcase_12 AC 3 ms
6,528 KB
testcase_13 AC 4 ms
6,400 KB
testcase_14 AC 3 ms
6,528 KB
testcase_15 AC 3 ms
6,656 KB
testcase_16 AC 4 ms
6,400 KB
testcase_17 AC 3 ms
6,528 KB
testcase_18 AC 4 ms
6,400 KB
testcase_19 AC 4 ms
6,528 KB
testcase_20 AC 3 ms
6,656 KB
testcase_21 AC 4 ms
6,528 KB
testcase_22 AC 4 ms
6,656 KB
testcase_23 AC 4 ms
6,528 KB
testcase_24 AC 4 ms
6,400 KB
testcase_25 AC 4 ms
6,528 KB
testcase_26 AC 4 ms
6,528 KB
testcase_27 AC 4 ms
6,400 KB
testcase_28 AC 4 ms
6,656 KB
testcase_29 AC 3 ms
6,528 KB
testcase_30 AC 4 ms
6,400 KB
testcase_31 AC 4 ms
6,528 KB
testcase_32 AC 4 ms
6,400 KB
testcase_33 AC 4 ms
6,400 KB
testcase_34 AC 4 ms
6,528 KB
testcase_35 AC 5 ms
6,400 KB
testcase_36 AC 6 ms
6,400 KB
testcase_37 AC 6 ms
6,400 KB
testcase_38 AC 5 ms
6,528 KB
testcase_39 AC 5 ms
6,400 KB
testcase_40 AC 4 ms
6,656 KB
testcase_41 AC 6 ms
6,528 KB
testcase_42 AC 5 ms
6,400 KB
testcase_43 AC 5 ms
6,400 KB
testcase_44 AC 5 ms
6,400 KB
testcase_45 AC 5 ms
6,400 KB
testcase_46 AC 5 ms
6,528 KB
testcase_47 AC 6 ms
6,528 KB
testcase_48 AC 4 ms
6,528 KB
testcase_49 AC 6 ms
6,400 KB
testcase_50 AC 6 ms
6,528 KB
testcase_51 AC 4 ms
6,528 KB
testcase_52 AC 5 ms
6,656 KB
testcase_53 AC 5 ms
6,528 KB
testcase_54 AC 5 ms
6,400 KB
testcase_55 AC 87 ms
9,600 KB
testcase_56 RE -
testcase_57 RE -
testcase_58 AC 71 ms
9,420 KB
testcase_59 AC 109 ms
10,496 KB
testcase_60 AC 64 ms
8,924 KB
testcase_61 RE -
testcase_62 RE -
testcase_63 RE -
testcase_64 AC 81 ms
9,472 KB
testcase_65 RE -
testcase_66 RE -
testcase_67 RE -
testcase_68 AC 106 ms
10,496 KB
testcase_69 RE -
testcase_70 RE -
testcase_71 AC 92 ms
9,472 KB
testcase_72 RE -
testcase_73 RE -
testcase_74 AC 118 ms
10,296 KB
testcase_75 RE -
testcase_76 AC 137 ms
10,880 KB
testcase_77 AC 90 ms
9,472 KB
testcase_78 AC 109 ms
9,856 KB
testcase_79 AC 83 ms
9,088 KB
testcase_80 RE -
testcase_81 RE -
testcase_82 AC 146 ms
11,008 KB
testcase_83 RE -
testcase_84 AC 132 ms
10,332 KB
testcase_85 AC 16 ms
6,784 KB
testcase_86 AC 123 ms
10,240 KB
testcase_87 RE -
testcase_88 AC 69 ms
8,576 KB
testcase_89 AC 163 ms
11,132 KB
testcase_90 AC 66 ms
8,536 KB
testcase_91 RE -
権限があれば一括ダウンロードができます

ソースコード

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];//遷移元となる前にdを1回だけ足しておきます
      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;
} 
0