# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
134968 | wilwxk | Split the sequence (APIO14_sequence) | C++14 | 2060 ms | 131076 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); 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++) dp[i][0]=-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]*soma[i-1];
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; int k=x;
while(respf.size()<x-1) {
respf.push_back(opt[ind][k]);
ind=opt[ind][k--];
}
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... |