# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
982553 | Error404 | Split the sequence (APIO14_sequence) | C++17 | 2051 ms | 23896 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 ll long long
#define f first
#define s second
#define pb push_back
int main(){
int n,parts;
cin >> n >> parts;
int a[n+1], pref[n+1];
for(int i = 1; i <= n; i++){
cin >> a[i];
}
pref[0]=0;
for(int i = 1; i <= n; i++){
pref[i]= pref[i-1]+a[i];
}
ll dp[n+1][parts+1];
int p[n+1][parts+1];
memset(dp,0,sizeof(dp));
memset(p,0,sizeof(p));
for(int i = 1; i <=n; i++){
for(int j = 1; j <= parts;j++){
for(int k = i; k >=1;k--){
ll val = dp[k-1][j-1] + (pref[i]-pref[k-1]) * (pref[n]-pref[i]);
if(dp[i][j] < val){
dp[i][j] = val;
p[i][j] = k-1;
}
}
}
}
ll pos = 0;
for(int i = 1; i <= n; i++){
if(dp[i][parts]> dp[pos][parts]) pos= i;
}
cout << dp[pos][parts]<< endl;
vector<int>ans;
int num = parts;
while(true){
ans.pb(pos);
pos= p[pos][parts];
parts--;
if(!pos)break;
}
reverse(ans.begin(),ans.end());
for(int i : ans){
cout << 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... |