# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
40509 | mohammad_kilani | Split the sequence (APIO14_sequence) | C++14 | 1165 ms | 17208 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 mod 1000000007
#define oo 1000000000
const double PI = acos(-1);
const int N = 10010 , K = 201;
int arr[N] , n , k;
long long dp[N][K] , sum[N] , last[N];
void buildpath(int i,int j){
if(i == n - 1 || j == k)
return;
for(int l=i+1;l<n;l++){
if(dp[i][j] == dp[l][j+1] + (sum[l] - sum[i]) * (sum[n] - sum[l])){
printf("%d ",l);
buildpath(l,j+1);
return;
}
}
}
int main(){
scanf("%d%d",&n,&k);
for(int i=0;i<n;i++){
scanf("%d",&arr[i]);
sum[i+1] = sum[i] + arr[i];
}
for(int i=0;i<k;i++)
dp[n-1][i] = -1e17;
for(int i=n-2;i>=0;i--){
for(int j=0;j<k;j++){
bool akbar = true;
last[i] = -1e18;
for(int l=i+1;l<n;l++){
last[l] = dp[l][j+1] + (sum[l] - sum[i]) * (sum[n] - sum[l]);
if(akbar == false && last[l] > last[l-1]) assert(false);
if(akbar == true && last[l] < last[l-1]) akbar = false;
dp[i][j] = max(dp[i][j],dp[l][j+1] + (sum[l] - sum[i]) * (sum[n] - sum[l]));
}
}
}
cout << dp[0][0] << endl;
buildpath(0,0);
puts("");
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... |