# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
365294 | saleh | Split the sequence (APIO14_sequence) | C++17 | 2069 ms | 9324 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;
const int MAXN = 100 * 1000 + 2, MAXK = 200 + 2;
int n, k, chi, lvl;
int par[MAXK][MAXN];
long long dp[2 + 2][MAXN], ps[MAXN];
void cal(int l = chi, int r = n + 1, int ll = chi, int rr = n) {
int mid = ((l + r) >> 1), md;
long long j;
for (int i = ll; i < mid && i < r; i++) if ((j = dp[1 - lvl][i] + ps[i] * (ps[mid] - ps[i])) > dp[lvl][mid]) {
dp[lvl][mid] = j;
md = i;
}
par[chi][mid] = md;
if (l < mid) cal(l, mid, ll, md);
if (mid + 1 < r) cal(mid + 1, r, md, rr);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
cin >> n >> k;
int a;
for (int i = 0; i < n; i++) {
cin >> a;
ps[i + 1] = ps[i] + a;
}
for (int i = 1; i <= k; i++) {
chi = i;
lvl = i & 1;
for (int j = i; j <= n; j++) dp[lvl][j] = -1;
cal();
}
cout << dp[k & 1][n] << '\n';
while (k > 0) {
cout << par[k][n] << ' ';
n = par[k][n];
k--;
}
return 0;
}
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... |