# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
477528 | PiejanVDC | Split the sequence (APIO14_sequence) | C++17 | 2086 ms | 31820 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;
signed main() {
int64_t n,k; cin>>n>>k;
vector<int64_t>pref(n+1);
pref[0]=0;
for(int64_t i = 0 ; i < n ; i++) {
int64_t x; cin>>x;
pref[i+1] = pref[i] + x;
}
int64_t res[n+1][k+1];
int64_t dp[n+1][k+1];
for(int64_t i = 0 ; i <= n ; i++)
dp[i][0] = 0;
for(int64_t i = 1 ; i <= k ; i++)
dp[0][i] = 0;
for(int64_t i = 1 ; i <= k ; i++) {
for(int64_t j = 1 ; j <= n ; j++) {
dp[j][i] = 0;
for(int64_t c = 1 ; c < j ; c++) {
//assert(c-1 >= 0 && i-1 >= 0 && j-1 >= 0);
if(dp[c][i-1] + (pref[n] - pref[j-1]) * (pref[j-1] - pref[c-1]) >= dp[j][i]) {
res[j][i] = c;
}
dp[j][i] = max(dp[j][i],dp[c][i-1] + (pref[n] - pref[j-1]) * (pref[j-1] - pref[c-1]));
}
}
}
int64_t mx=0;
int64_t node;
vector<int64_t>ans;
for(int64_t i = 0 ; i <= n ; i++) {
if(dp[i][k] >= mx) {
mx=dp[i][k];
node = i;
}
}
cout << mx << "\n";
for(int i = 0 ; i < k ; i++) {
cout << node-1 << " ";
node = res[node][k - i];
}
}
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... |