# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
134951 | wilwxk | Split the sequence (APIO14_sequence) | C++14 | 2051 ms | 41728 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;
typedef long long ll;
const int MAXN=1e5+5;
const ll INF=1e18;
ll dp[MAXN][205];
int opt[MAXN][205];
ll soma[MAXN];
ll v[MAXN];
int n, x;
int main() {
scanf("%d %d", &n, &x);
for(int i=1; i<=n; i++) scanf("%lld", &v[i]);
for(int i=1; i<=n; i++) soma[i]=soma[i-1], soma[i]+=v[i];
dp[0][0]=0; for(int i=1; i<=x; i++) dp[0][i]=-INF;
for(int i=1; i<=n; i++) {
for(int j=1; j<=x; j++) {
dp[i][j]=dp[i-1][j-1]+v[i];
opt[i][j]=i-1;
for(int k=0; k<i; k++) {
ll val=dp[k][j-1]+(soma[i]-soma[k])*soma[k];
if(val>=dp[i][j]) {
dp[i][j]=val;
opt[i][j]=k;
}
}
// printf("%d %d >> %lld // %d\n", i, j, dp[i][j], opt[i][j]);
}
}
printf("%lld\n", dp[n][x]);
vector<int> respf;
int ind=n;
while(opt[ind][x]!=0) {
respf.push_back(opt[ind][x]);
ind=opt[ind][x--];
}
reverse(respf.begin(), respf.end());
for(auto cur : respf) printf("%d ", cur);
}
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... |