# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
108682 | autumn_eel | Split the sequence (APIO14_sequence) | C++14 | 2053 ms | 99412 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 rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
ll dp[20000][300];
int prv[2000][300];
ll a[20000];
int main(){
int n,K;cin>>n>>K;K++;
ll cnt=0;
rep(i,n){
scanf("%lld",&a[i]);
cnt+=a[i];
}
memset(dp,0x3f,sizeof(dp));
dp[0][0]=0;
rep(i,n)rep(j,K){
ll sum=0;
for(int k=i;k<n;k++){
sum+=a[k];
if(dp[k+1][j+1]>dp[i][j]+sum*sum){
dp[k+1][j+1]=dp[i][j]+sum*sum;
prv[k+1][j+1]=i;
}
}
}
ll res=(cnt*cnt-dp[n][K])/2;
int x=n,y=K;
vector<int>ans;
while(1){
x=prv[x][y];
y--;
if(!x)break;
ans.push_back(x);
}
reverse(ans.begin(),ans.end());
cout<<res<<endl;
rep(i,ans.size()){
if(i)printf(" ");
printf("%d",ans[i]);
}
puts("");
}
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... |