Submission #1110531

#TimeUsernameProblemLanguageResultExecution timeMemory
1110531simona1230Split the sequence (APIO14_sequence)C++17
22 / 100
20 ms11088 KiB
#include <bits/stdc++.h> using namespace std; long long n,k; long long a[200001]; long long dp[64][64][64]; long long p[64]; void read() { cin>>n>>k; for(long long i=1;i<=n;i++) { cin>>a[i]; p[i]=p[i-1]+a[i]; } } long long idx[64][64][64]; long long cntl[64][64][64]; vector<long long> ans; void rec(long long i,long long j,long long c) { if(c==0)return; ans.push_back(idx[i][j][c]); rec(i,idx[i][j][c],cntl[i][j][c]); rec(idx[i][j][c]+1,j,c-cntl[i][j][c]-1); } void solve() { for(long long l=1;l<=n;l++) { for(long long i=1;i<=n;i++) { long long j=i+l-1; if(j>n)continue; for(long long c=1;c<=k;c++) { // transition for(long long mid=i;mid<j;mid++) { for(long long c1=c-1;c1<c;c1++) { long long c2=c-c1-1; long long curr=dp[i][mid][c1]+dp[mid+1][j][c2]+(p[j]-p[mid])*(p[mid]-p[i-1]); if(curr>=dp[i][j][c]) { dp[i][j][c]=curr; idx[i][j][c]=mid; cntl[i][j][c]=c1; } } } /// } } } cout<<dp[1][n][k]<<endl; rec(1,n,k); sort(ans.begin(),ans.end()); for(long long i=0;i<k;i++) cout<<ans[i]<<" "; cout<<endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); read(); solve(); return 0; } /* 7 3 4 1 3 4 0 2 3 */
#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...