# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
135098 | CaroLinda | Split the sequence (APIO14_sequence) | C++14 | 163 ms | 2936 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 lp(i,a,b) for(int i=a;i<b;i++)
#define pii pair<int,int>
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
const ll inf = 1e15 ;
const int MAXN = 1010 ;
const int MAXK = 210 ;
using namespace std ;
int n , k ;
ll pref[MAXN] , dp[MAXN][MAXK] ;
int cut[MAXN][MAXK] ;
vector<int> ans ;
ll get(int i , int j) { return pref[j] - pref[i-1] ; }
void buildAns(int ini, int c)
{
if(c==0) return ;
ans.pb( cut[ini][c] ) ;
buildAns(cut[ini][c]+1,c-1) ;
}
int main()
{
scanf("%d%d", &n , &k ) ;
lp(i,1,n+1) scanf("%lld", &pref[i] ) ;
lp(i,1,n+1) pref[i] += pref[i-1] ;
for(int c = 1 ; c <= k ; c++)
{
for(int i = n ; i > 0 ; i-- )
{
if( n - i < c ) { dp[i][c] = -inf ; continue ; }
for(int j = i ; j < n ; j++ )
{
ll ganho = dp[j+1][c-1] + get(i,j)*get(j+1,n) ;
if(ganho > dp[i][c])
cut[i][c] = j , dp[i][c] = ganho ;
}
}
}
buildAns(1,k) ;
printf("%lld\n" , dp[1][k]);
lp(i,0,k) printf("%d ", ans[i]) ;
printf("\n");
}
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... |