# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
100230 | TadijaSebez | Split the sequence (APIO14_sequence) | C++11 | 1443 ms | 82040 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;
#define ll long long
const int N=100050;
const int K=205;
const ll inf=1e18;
int a[N];
ll sum[N];
ll dp[N][2];
int best[K][N];
void Solve(int k, int ss, int se, int l, int r)
{
if(ss>se) return;
int mid=ss+se>>1;
dp[mid][k&1]=-inf;
for(int i=l;i<=min(r,mid);i++)
{
ll tmp=dp[i-1][(k&1)^1]+(sum[mid]-sum[i-1])*sum[i-1];
if(tmp>dp[mid][k&1]) dp[mid][k&1]=tmp,best[k][mid]=i;
}
Solve(k,ss,mid-1,l,best[k][mid]);
Solve(k,mid+1,se,best[k][mid],r);
}
int main()
{
int n,k;
scanf("%i %i",&n,&k);k++;
for(int i=1;i<=n;i++) scanf("%i",&a[i]),sum[i]=sum[i-1]+a[i],dp[i][0]=-inf;
for(int i=1;i<=k;i++) Solve(i,i,n,i,n);
printf("%lld\n",dp[n][k&1]);
vector<int> ans;
for(int i=n,j=k;i>0;i=best[j][i]-1,j--) ans.push_back(i);
reverse(ans.begin(),ans.end());
ans.pop_back();
for(int i:ans) printf("%i ",i);
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... |