# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
416245 | DEQK | Split the sequence (APIO14_sequence) | C++17 | 1062 ms | 80944 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 = 100100;
int n, k;
ll a[N];
ll dp[N][2];
int p[201][N];
int cur;
void solve(int l,int r,int tl,int tr) {
if(l > r) return;
int m = l + r >> 1;
for(int i = tl; i < min(m, tr + 1); i++) {
if(dp[m][1] <= dp[i][0] + a[i] * (a[m] - a[i])) {
dp[m][1] = dp[i][0] + a[i] * (a[m] - a[i]);
p[cur][m] = i;
}
}
solve(l, m - 1, tl, p[cur][m]);
solve(m + 1, r, p[cur][m], tr);
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> n >> k;
for(int i = 1; i <= n; ++i) {
cin >> a[i];
a[i] += a[i - 1];
}
for(int j = 1; j <= k; j++) {
cur = j;
solve(1, n, 1, n);
for(int i = 1; i <= n; i++) {
dp[i][0] = dp[i][1];
dp[i][1] = 0;
}
}
cout << dp[n][0] << "\n";
int pos = n;
for(int j = k; j; j--) {
cout << p[j][pos] << " ";
pos = p[j][pos];
}
}
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... |