Submission #112114

#TimeUsernameProblemLanguageResultExecution timeMemory
112114_demon_Split the sequence (APIO14_sequence)C++14
50 / 100
152 ms3676 KiB
#include <bits/stdc++.h> using namespace std; long long n,k; long long a[1009]; long long dp[1009][209]; long long p[1009][209]; long long sum[1009]; int main(){ cin>>n>>k; for(int i=1;i<=n;i++)cin>>a[i]; for(int i=1;i<=n;i++)sum[i]=sum[i-1]+a[i]; for(int i=1;i<=n;i++){ long long crnt=0; for(long long j=i;j>=1;j--){ crnt+=a[j]; for(int K=1;K<=k+1;K++){ if(dp[i][K]<dp[j-1][K-1]+crnt*(sum[n]-sum[i])){ dp[i][K]=dp[j-1][K-1]+crnt*(sum[n]-sum[i]); p[i][K]=j-1; } if(dp[i][K]==dp[j-1][K-1]+crnt*(sum[n]-sum[i])){ dp[i][K]=dp[j-1][K-1]+crnt*(sum[n]-sum[i]); p[i][K]=max(p[i][K],j-1); } } } } cout<<dp[n][k+1]<<endl; vector<int>v; int ii=n;int kk=k+1; while(kk>1){ v.push_back(p[ii][kk]); ii=p[ii][kk]; kk--; } reverse(v.begin(),v.end()); for(int i=0;i<v.size();i++){ cout<<v[i]<<" "; } cout<<endl; }

Compilation message (stderr)

sequence.cpp: In function 'int main()':
sequence.cpp:37:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=0;i<v.size();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...