# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
81354 | kimjg1119 | Split the sequence (APIO14_sequence) | C++17 | 23 ms | 13664 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define MAXN 100005
using namespace std;
typedef long long ll;
typedef pair<ll,int> pli;
typedef struct CHT{
ll la[MAXN], lb[MAXN]; int lz[MAXN];
int stkn=0,pt=1;
void insert(ll a, ll b, int z){
while(stkn>pt && (lb[stkn]-b)*(la[stkn]-la[stkn-1])<(a-la[stkn])*(lb[stkn-1]-lb[stkn])) stkn--;
la[++stkn]=a;
lb[stkn]=b;
lz[stkn]=z;
}
pli query(ll x){
while(pt<stkn && (lb[pt]-lb[pt+1])<(la[pt+1]-la[pt])*x) pt++;
return make_pair(la[pt]*x+lb[pt],lz[pt]);
}
}CHT;
CHT c[205];
ll a[MAXN],D[205][MAXN],S[MAXN];
int pre[205][MAXN];
int main(){
int n,k;
scanf("%d %d",&n,&k);
for(int i=1;i<=n;i++) scanf("%lld",&a[i]), S[i]=S[i-1]+a[i];
for(int i=1;i<=k;i++) c[i].insert(0,0,0);
for(int i=1;i<=k;i++){
for(int j=1;j<=n;j++){
pli temp=c[i].query(S[j]);
D[i][j]=temp.first;
pre[i][j]=temp.second;
c[i].insert(S[j],D[i-1][j]-S[j]*S[j],j);
}
}
printf("%lld\n",D[k][n]);
int here=n;
for(int i=1;i<=k;i++){
printf("%d ",pre[k-i+1][here]);
here=pre[k][here];
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |