Submission #37609

#TimeUsernameProblemLanguageResultExecution timeMemory
37609mr_bananaSplit the sequence (APIO14_sequence)C++14
0 / 100
0 ms1840 KiB
#include <iostream> #define int long long using namespace std; const int MN=1e5+10; long long dp[2][MN]; int a[MN]; int ps[MN]; int dp2[MN][201]; long long sq(int x){ return 1ll*x*x; } void solve(int d,int l,int r,int ol,int orr){ if(l>=r){ return ; } int mid=(l+r)/2; int o=ol; for(int i=ol;i<orr && i<mid;i++){ int tmp=dp[1][mid]; dp[1][mid]=max(dp[1][mid],dp[0][i]+1ll*(ps[mid+1]-ps[i+1])*ps[i+1]); if(dp[1][mid]>tmp){ o=i; } } dp2[mid][d]=o; solve(d,l,mid,ol,o+1); solve(d,mid+1,r,o,orr); } int32_t main() { ios::sync_with_stdio(0); int n,k; cin>>n>>k; for(int i=0;i<n;i++){ cin>>a[i]; ps[i+1]=ps[i]+a[i]; } for(int i=1;i<=k;i++){ solve(i,0,n,0,n); for(int j=0;j<n;j++){ dp[0][j]=dp[1][j]; dp[1][j]=0; } } cout<<dp[0][n-1]<<endl; int x=n-1; for(int i=k;i>0;i--){ cout<<dp2[x][i]+1<<" "; x=dp2[x][i]; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...