# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
282643 | jainbot27 | Split the sequence (APIO14_sequence) | C++17 | 2086 ms | 32512 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 int int64_t
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0);
int n, k;
cin >> n >> k;
vector<int> a(n+1), p(n+1);
for(int i=0; i < n; i++){
cin >> a[i+1];
p[i+1] = p[i] + a[i+1];
}
vector<vector<int64_t>> dp(n+1, vector<int64_t>(k+1, 0));
vector<vector<int64_t>> par(n + 1, vector<int64_t>(k + 1, 0));
int besti, bestj;
int64_t ans = -1;
for(int i=1; i <= n; i++){
for(int j=1; j <= k; j++){
for(int l = 0; l < i; l++){
if(dp[i][j] < dp[l][j-1] + (int64_t)(p[i]-p[l]) * (p[n]-p[i]) && !(j>1&&l==0)){
dp[i][j] = dp[l][j-1] + (int64_t)(p[i] - p[l]) * (p[n] - p[i]);
par[i][j] = l;
}
if(j==k){
if(ans < dp[i][j]){
ans = dp[i][j];
besti = i; bestj = j;
}
}
//cerr << "I: " << i << " J: " << j << " K: " << k << " P[i]: " << p[i] << " P[l-1] " << p[l-1] << "\n";
}
//cerr << "(" << i << "," << j << ") " << dp[i][j] << "\n";
}
}
cout << ans << "\n";
assert(bestj == k);
vector<int> res;
for(int i=0; i < k; i++){
res.push_back(besti);
besti = par[besti][bestj];
bestj--;
}
reverse(res.begin(), res.end());
for(int i : res){
cout << i << " ";
}
cout << "\n";
}
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... |