Submission #92405

#TimeUsernameProblemLanguageResultExecution timeMemory
92405VardanyanSplit the sequence (APIO14_sequence)C++14
49 / 100
428 ms132096 KiB
//#pragma GCC optimize "-O3" #include<bits/stdc++.h> using namespace std; const int N = 1000*100+5; const long long INF = 1000000000000000000; int a[N]; long long pref[N]; pair<long long,int> dp[208][N]; int par[208][N]; void get(int kk,int l,int r,int s,int e){ if(l>r) return; int i = (l+r)/2; int pos = 0; for(int j = s;j<=e;j++){ if(dp[kk-1][j].first+(pref[i]-pref[j])*pref[j]>=dp[kk][i].first){ dp[kk][i].first = dp[kk-1][j].first+(pref[i]-pref[j])*pref[j]; dp[kk][i].second = j; pos = j; } } get(kk,l,i-1,s,pos); get(kk,i+1,r,pos,e); } int main() { int n,k; scanf("%d%d",&n,&k); for(int i = 1;i<=n;i++) scanf("%d",&a[i]); for(int i = 1;i<=n;i++) pref[i] = pref[i-1]+a[i]; // node* old = new node(); // node* nold = new node(); for(int kk = 1;kk<=k;kk++){ /*if(kk == 1){ for(int i = 1;i<=n;i++){ for(int j = dp[kk-1][i].second;j<i;j++){ if(dp[kk-1][j].first+(pref[i]-pref[j])*pref[j]>=dp[kk][i].first){ dp[kk][i].first = dp[kk-1][j].first+(pref[i]-pref[j])*pref[j]; dp[kk][i].second = j; } } } continue; }*/ get(kk,kk,n,0,n); } printf("%lld\n",dp[k][n].first); int kk = k; int nn = n; while(kk>0){ printf("%d\n",dp[kk][nn].second); nn = dp[kk][nn].second; kk--; } printf("\n"); return 0; }

Compilation message (stderr)

sequence.cpp: In function 'int main()':
sequence.cpp:29:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&k);
     ~~~~~^~~~~~~~~~~~~~
sequence.cpp:30:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i = 1;i<=n;i++) scanf("%d",&a[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...