# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1022460 | daffuwu | Split the sequence (APIO14_sequence) | C++14 | 2035 ms | 8612 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 fr first
#define sc second
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int n, k, opt[100002][202];
long long ps[100069], dp[100069][2], val;
int main()
{
int i, j, c;
scanf("%d%d", &n, &k);
k++;
for (i=1; i<=n; i++)
{
scanf("%lld", ps+i);
ps[i] += ps[i-1];
dp[i][0] = -1e15;
}
for (c=1; c<=k; c++)
{
dp[0][c%2] = -1e15;
for (i=1; i<=n; i++)
{
dp[i][c%2] = 0;
for (j=i-1; j>=0; j--)
{
val = dp[j][(c+1)%2]+(ps[i]-ps[j])*ps[j];
if (val>dp[i][c%2])
{
dp[i][c%2] = val;
opt[i][c] = j;
}
}
}
}
printf("%lld\n", dp[n][k%2]);
for (i=n, c=k; c>=2; i=opt[i][c], c--)
{
printf("%d ", opt[i][c]);
}
printf("\n");
}
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... |