Submission #523604

# Submission time Handle Problem Language Result Execution time Memory
523604 2022-02-07T22:41:52 Z DanerZein Discharging (NOI20_discharging) C++14
0 / 100
277 ms 15908 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX_N=1e6+10;
const int MAX_P=MAX_N*4;
const int MAX=1e9;
ll val[MAX_N];
ll n;
ll mdp[MAX_N];
ll coste(ll i,ll x){
  ll tx=n+1; tx*=x;
  ll b=mdp[i-1]-i*x;
  return tx+b;
}
int time(int i,int j){
  int l=0,r=1e6+10;
  while(r-l>1){
    int mid=(l+r)/2;
    if(coste(i,mid)>=coste(j,mid)) r=mid;
    else l=mid;
  }
  return r;
}
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin>>n;
  for(int i=0;i<n;i++){
    int a; cin>>a;
    val[i]=a;
  }
  mdp[0]=0;
  deque<int> dq;
  
  for(int i=1;i<=n;i++){
    int t=dq.size();
    while(t>=3 && time(dq[t-2],dq[t-1])>=time(dq[t-2],i)){
      dq.pop_back(); t--;
    }
    dq.push_back(i);
    while(dq.size()>=2 && coste(dq[0],val[i-1])>=coste(dq[1],val[i-1])){
      dq.pop_front();
    }
    mdp[i]=coste(dq.front(),val[i-1]);
  }
  cout<<mdp[n]<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 0 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 277 ms 15908 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 0 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 0 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -