# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
37554 | Talant | Split the sequence (APIO14_sequence) | C++11 | 1116 ms | 82880 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 ll long long
using namespace std;
const int N = (int)1e5 + 7;
ll dp[2][N];
ll p[N];
int pr[201][N];
int n;
inline ll calc (int r,int l) {
return p[l] * (p[r] - p[l]);
}
inline int min(int a, int b)
{
return a < b ? a : b;
}
void compute (int k,int l,int r,int L,int R) {
if (l > r) return;
int m = (l + r) >> 1;
dp[k & 1][m] = 0;
int &opt = pr[k][m];
for (int i = L; i <= min(m - 1,R); i ++) {
ll now = dp[k & 1 ^ 1][i] + calc(m,i);
if (now >= dp[k & 1][m]) {
dp[k & 1][m] = now;
opt = i;
}
}
compute (k, l,m - 1, L, opt);
compute (k, m + 1, r, opt, R);
}
int kk;
main () {
scanf ("%d%d", &n,&kk);
for (int i = 1; i <= n; i ++) {
scanf ("%lld", &p[i]);
p[i] += p[i - 1];
}
for (int i = 1; i <= kk; i ++)
compute (i,1,n,1,n - 1);
printf("%lld\n", dp[kk & 1][n]);
while (kk > 0) {
printf("%d ", pr[kk][n]);
n = pr[kk][n];
kk --;
}
}
/**
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... |