# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
126940 | AQT | Split the sequence (APIO14_sequence) | C++14 | 1787 ms | 83548 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;
int N, K;
long long pre[100005];
long long dp[100005][2];
int par[100005][205];
inline void solve(int l, int r, int lb, int ub, int lvl){
if(l > r){
return;
}
int mid = l+r>>1;
for(int i = lb; i<=min(mid-1, ub); i++){
if(dp[mid][lvl&1] <= dp[i][lvl&1^1] + pre[i]*(pre[mid] - pre[i])){
dp[mid][lvl&1] = dp[i][lvl&1^1] + pre[i]*(pre[mid] - pre[i]);
par[mid][lvl] = i;
}
}
solve(l, mid-1, lb, par[mid][lvl], lvl);
solve(mid+1, r, par[mid][lvl], ub, lvl);
}
int main(){
cin.sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> N >> K;
for(int i = 1; i<=N; i++){
cin >> pre[i];
pre[i] += pre[i-1];
}
for(int k = 1; k<=K; k++){
solve(k+1, N, k, N, k);
}
cout << dp[N][K&1] << "\n";
int crnt = N;
for(int k = K; k>=1; k--){
cout << par[crnt][k] << " ";
crnt = par[crnt][k];
}
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... |