# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
174683 | CaroLinda | Split the sequence (APIO14_sequence) | C++14 | 183 ms | 131072 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 debug printf
#define lp(i,a,b) for(int i = a ; i < b ; i++ )
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
#define ll long long
#define sz size()
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define tiii tuple<int,int,int>
#define mkt make_tuple
const int MAXN = 1e5+10 , MAXK = 210 ;
using namespace std ;
int n , k ;
int a[MAXN] ;
ll sufSum[MAXN] ;
ll dp[MAXN][MAXK] , myOpt[MAXN][MAXK] ;
void calcDp(int l , int r , int optmin , int optmax, int am )
{
if( r < l ) return ;
int mid = (l+r)>>1 ;
ll opt , val=0 , cur ;
lp(i,max(optmin,mid),optmax+1)
{
cur = dp[i][am-1] + (sufSum[mid] - sufSum[i])*sufSum[i] ;
if( cur > val ) val = cur, opt = i ;
}
dp[mid][am] = val ;
myOpt[mid][am] = opt ;
calcDp(l,mid-1, optmin, opt , am ) ;
calcDp(mid+1, r, opt, optmax, am ) ;
}
int main()
{
scanf("%d%d", &n, &k) ;
lp(i,1,n+1) scanf("%d", &a[i] ) ;
for(int i = n ; i > 0 ; i-- ) sufSum[i] = sufSum[i+1] + a[i] ;
lp(i,1,k+1) calcDp(1,n - i,1,n-i+1,i) ;
printf("%lld\n", dp[1][k] ) ;
vector<int> ans ;
int cur = 1 ;
for(int i = k ; i > 0 ; i-- )
{
cur = myOpt[cur][i] ;
ans.pb(cur-1) ;
}
sort(all(ans)) ;
for(int i : ans ) printf("%d " , 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... |