# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
208009 | rzbt | Split the sequence (APIO14_sequence) | C++14 | 49 ms | 1400 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>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define MAXN 1005
#define MAXK 55
typedef long long ll;
using namespace std;
ll n,u;
ll dp[MAXN][MAXK];
ll niz[MAXN];
ll suma[MAXN];
ll sec[MAXN][MAXK];
ll resi(ll d,ll k){
if(dp[d][k]!=-1)return dp[d][k];
if(k==0 || d==1){
//printf(" %lld %lld %lld %lld\n",l,d,k,dp[l][d][k]);
return dp[d][k]=0;
}
for(ll i=k+1;i<=d;i++){
ll tr=suma[i-1]*(suma[d]-suma[i-1])+resi(i-1,k-1);
if(tr>dp[d][k]){
sec[d][k]=i-1;
dp[d][k]=tr;
}
}
//printf(" %lld %lld %lld %lld\n",l,d,k,dp[l][d][k]);
return dp[d][k];
}
int main()
{
scanf("%lld %lld", &n, &u);
for(ll i=0;i<=n;i++){
for(ll j=0;j<=u;j++){
dp[i][j]=-1;
}
}
for(ll i=1;i<=n;i++)
scanf("%lld",niz+i);
for(ll i=1;i<=n;i++)
suma[i]=suma[i-1]+niz[i];
printf("%lld\n",resi(n,u));
ll poc=n;
for(ll i=u;i>0;i--){
poc=sec[poc][i];
printf("%lld ",poc);
}
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... |