# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
403036 | Waratpp123 | Split the sequence (APIO14_sequence) | C++14 | 879 ms | 81764 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>
using namespace std;
long long a[100010],qs[100010],dp[2][100010];
int p[205][100010],n,k;
void play(int st,int l,int r,int optl,int optr){
int mid=(l+r)/2,pos,i;
long long mi=1e18;
if(l>r) return;
for(i=optl;i<=min(mid,optr);i++){
if(dp[1-st%2][i-1]+(qs[mid]-qs[i-1])*(qs[mid]-qs[i-1])<=mi){
mi=dp[1-st%2][i-1]+(qs[mid]-qs[i-1])*(qs[mid]-qs[i-1]);
pos=i;
}
}
dp[st%2][mid]=mi;
p[st][mid]=pos-1;
play(st,l,mid-1,optl,pos);
play(st,mid+1,r,pos,optr);
}
int main(){
int i,j,now;
scanf("%d %d",&n,&k);
for(i=1;i<=n;i++){
scanf("%lld",&a[i]);
qs[i]=qs[i-1]+a[i];
}
for(i=1;i<=n;i++){
dp[0][i]=qs[i]*qs[i];
}
for(i=1;i<=k;i++){
play(i,1,n,1,n);
}
printf("%lld\n",(qs[n]*qs[n]-dp[k%2][n])/2);
now=n;
for(i=k;i>=1;i--){
printf("%d ",p[i][now]);
now=p[i][now];
}
return 0;
}
/*
7 3
4 1 3 4 0 2 3
*/
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... |