# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
286501 | BeanZ | Split the sequence (APIO14_sequence) | C++14 | 2081 ms | 1408 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 ll long long
#define endl '\n'
const int N = 1e5 + 5;
ll dp[N][2];
ll opt[N][205];
ll a[N];
void DP(ll k, ll l, ll r, ll optl, ll optr){
if (l > r) return;
ll mid = (l + r) >> 1;
dp[mid][1] = -1e18;
ll best = optl;
for (int i = optl; i <= min(r - 1, optr); i++){
if (dp[mid][1] < (dp[i][0] + a[i] * (a[mid] - a[i]))){
dp[mid][1] = dp[i][0] + a[i] * (a[mid] - a[i]);
opt[mid][k] = i;
}
}
if (l == r) return;
DP(k, l, mid, optl, best);
DP(k, mid, r, best, optr);
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
if (fopen("VietCT.INP", "r")){
freopen("VietCT.INP", "r", stdin);
freopen("VietCT.OUT", "w", stdout);
}
ll n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++) cin >> a[i], a[i] = a[i] + a[i - 1];
for (int i = 1; i <= k; i++){
DP(i, 1, n, 1, n);
for (int j = 1; j <= n; j++){
dp[j][0] = dp[j][1];
}
}
cout << dp[n][1] << endl;
for (int i = k; i >= 1; i--){
cout << opt[n][i] << " ";
n = opt[n][i];
}
}
/*
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... |