# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1073037 | KasymK | Split the sequence (APIO14_sequence) | C++17 | 109 ms | 2828 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 ff first
#define ss second
#define all(v) v.begin(), v.end()
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pli pair<ll, int>
#define wr puts("----------------")
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const int N = 1005;
const int K = 205;
int v[N], par[N], id[N][K];
ll dp[N][K];
int main(){
// freopen("file.txt", "r", stdin);
int n, k;
scanf("%d%d", &n, &k);
for(int i = 1; i <= n; ++i){
int x;
scanf("%d", &x);
v[i] = x;
}
for(int i = 1; i <= n; ++i)
par[i] = par[i-1]+v[i];
for(int i = 1; i <= n; ++i)
for(int j = 0; j < i; ++j)
for(int x = 1; x <= min(k, i); ++x)
if(umax(dp[i][x], dp[j][x-1]+(par[i]-par[j])*(par[n]-par[i])))
id[i][x] = j;
ll answer = 0;
for(int i = 1; i <= n; ++i)
umax(answer, dp[i][k]);
int d = 0, x = k;
for(int i = 1; i <= n; ++i)
if(dp[i][k] == answer){
d = i;
break;
}
vector<int> A;
while(x){
A.pb(d);
d = id[d][x];
--x;
}
for(int &i : A){
if(i == 0)
i = 1;
else if(i == n)
i = n-1;
}
printf("%lld\n", answer);
for(int i = k-1; i >= 0; --i)
printf("%d ", A[i]);
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... |