# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
26479 | zoomswk | Split the sequence (APIO14_sequence) | C++14 | 1796 ms | 83540 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 <stdio.h>
int min(int a, int b){ return a < b ? a : b; }
int n;
long long a[100005];
long long dp[100005][2];
int opt[100005][205];
void conquer(int l, int r, int lv, int opt_l, int opt_r){
if(l > r) return;
int mid = (l+r)>>1;
for(int i=opt_l; i<=min(mid-1, opt_r); i++){
long long val = dp[i][(lv-1)&1] + (a[mid]-a[i])*(a[n]-a[mid]);
if(val >= dp[mid][lv&1]) dp[mid][lv&1] = val, opt[mid][lv] = i;
}
conquer(l, mid-1, lv, opt_l, opt[mid][lv]);
conquer(mid+1, r, lv, opt[mid][lv], opt_r);
return;
}
int main(){
int k;
scanf("%d%d", &n, &k);
for(int i=1; i<=n; i++) scanf("%lld", &a[i]), a[i] += a[i-1];
for(int i=1; i<=k; i++){
for(int j=1; j<=n; j++) dp[j][i&1] = 0;
conquer(1, n, i, 0, n);
}
long long res = 0;
int res_pos = 0;
for(int i=1; i<n; i++){
if(dp[i][k&1] >= res){
res = dp[i][k&1];
res_pos = i;
}
}
printf("%lld\n", res);
while(k){
printf("%d ", res_pos);
res_pos = opt[res_pos][k];
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... |