# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
209961 | my99n | Split the sequence (APIO14_sequence) | C++14 | 2107 ms | 112248 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;
long long a[100100], s[100100], dp[2][100100];
vector<int> mxk[2][100100];
void solve (int i, int l, int r, int kmin, int kmax) {
if (r < l) return;
int mid = (l+r)/2, m = -1;
for (int k = kmin; k <= kmax; k++) {
long long nw = dp[i^1][k] + (s[mid]-s[k])*(s[k]-s[0]);
if (nw >= dp[i][mid]) {
dp[i][mid] = nw;
m = k;
}
}
mxk[i][mid].clear();
mxk[i][mid].push_back(m);
for (auto x : mxk[i^1][m]) mxk[i][mid].push_back(x);
solve(i, l, mid-1, kmin, m); solve(i, mid+1, r, m, kmax);
}
int main(){
int n, k; scanf("%d %d", &n, &k);
for (int i = 1; i <= n; i++) scanf("%lld", &a[i]), s[i] = s[i-1]+a[i];
for (int i = 1; i <= k; i++) solve(i%2, 1, n, 1, n-1);
printf("%lld\n", dp[k%2][n]);
for (auto x : mxk[k%2][n]) printf("%d ", x);
return 0;
}
// 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... |