Submission #523608

# Submission time Handle Problem Language Result Execution time Memory
523608 2022-02-08T00:26:12 Z DanerZein Discharging (NOI20_discharging) C++14
0 / 100
277 ms 23748 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAX_N=1e6+10;
const ll MAX=1e9;
ll val[MAX_N];
ll n,c;
ll mdp[MAX_N];
ll pre[MAX_N];
ll coste(ll i,ll x){
  /* ll d=val[i]-x;
     return d*d+pre[i];*/
  ll tx=n+1; tx*=x;
  ll b=pre[i]-i*x;
  return tx+b;
}
ll time(ll i,ll j){
  ll l=val[i],r=val[i];
  while(coste(i,r)<coste(j,r)){
    l=r+1;
    r*=2;
  }
  while(r>l){
    ll mid=(l+r)/2;
    if(coste(i,mid)>=coste(j,mid)) r=mid;
    else l=mid+1;
  }
  return r;
}
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin>>n;
  for(ll i=0;i<n;i++){
    ll a; cin>>a;
    val[i]=a;
  }
  mdp[0]=0;
  ll dq[MAX_N];
  ll ba,fr;
  fr=0; ba=0;
  ll bp=0;
  for(ll i=0;i<n;i++){
    pre[i]=bp;
    
    while(ba-fr>=2 && time(dq[ba-2],dq[ba-1])>=time(dq[ba-2],i)){
      //dq.pop_back(); t--;
      ba--;
    }
    //dq.push_back(i);
    dq[ba++]=i;
    while(fr+1<ba && coste(dq[fr],val[i])>=coste(dq[fr+1],val[i])){
      fr++;
    }
    // mdp[i]=min(a,b);
    bp=coste(dq[fr],val[i]);
  }
  cout<<bp<<endl;
}
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 8140 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 8168 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 8168 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 277 ms 23748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 8140 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 8140 KB Output isn't correct
2 Halted 0 ms 0 KB -