# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
93249 | emil_physmath | Split the sequence (APIO14_sequence) | C++17 | 2048 ms | 54320 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 <iostream>
#include <stdio.h>
using namespace std;
const int MAXN=100001, MAXK=301;
long long a[MAXN], prefSum[MAXN], dp[MAXN][MAXK];
int lt[MAXN][MAXK];
long long sum(int l, int r);
int main()
{
int n, k;
cin>>n>>k;
for (int i=0; i<n; i++)
scanf("%lld", a+i);
prefSum[0]=a[0];
for (int i=1; i<n; i++) prefSum[i]=prefSum[i-1]+a[i];
for (int i=0; i<n; i++)
for (int curk=1; curk<=min(k, i); curk++)
{
dp[i][curk]=lt[n-1][curk]=-1;
for (int prevSpl=0; prevSpl<i; prevSpl++)
if (curk-1<=prevSpl && dp[prevSpl][curk-1]+sum(0, prevSpl)*sum(prevSpl+1, i)>dp[i][curk])
{
dp[i][curk]=dp[prevSpl][curk-1]+sum(0, prevSpl)*sum(prevSpl+1, i);
lt[i][curk]=prevSpl;
}
}
cout<<dp[n-1][k]<<'\n';
int cur=n-1;
int cnt=0;
while (k)
{
cur=lt[cur][k];
k--;
printf("%d ", cur+1);
cnt++;
}
cout<<'\n';
char I;
cin >> I;
return 0;
}
long long sum(int l, int r)
{
return l ? prefSum[r]-prefSum[l-1] : prefSum[r];
}
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... |