# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
403023 | Waratpp123 | Split the sequence (APIO14_sequence) | C++14 | 30 ms | 4536 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-1;i<=min(mid-1,optr-1);i++){
if(dp[1-st%2][i]+(qs[mid]-qs[i])*(qs[mid]-qs[i])<mi){
mi=dp[1-st%2][i]+(qs[mid]-qs[i])*(qs[mid]-qs[i]);
pos=i;
}
}
dp[st%2][mid]=mi;
p[st][mid]=pos;
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... |