Submission #243723

#TimeUsernameProblemLanguageResultExecution timeMemory
243723HuyQuang_re_ZeroSplit the sequence (APIO14_sequence)C++14
0 / 100
40 ms33432 KiB
#include <bits/stdc++.h> #define db long long #define N 10002 using namespace std; struct pt { db A,B; int vt; }; double giao(pt x,pt y) { return (y.B-x.B)*1.0/(x.A-y.A); } pt st[N]; long long g[N],f[N][202]; int i,j,n,sl,top,k,tr[N][202],d[N]; int main() { // freopen("ntu.inp","r",stdin); // freopen("ntu.out","w",stdout); cin>>n>>k; k++; memset(f,-1,sizeof(f)); f[0][0]=0; for(i=1;i<=n;i++) { cin>>g[i]; g[i]+=g[i-1]; } for(sl=1;sl<=k;sl++) { top=0; j=1; for(i=0;i<=n;i++) { if(top>0) j=min(j,top); if(top>0) { while(j<top && st[j].A*g[i]+st[j].B<st[j+1].A*g[i]+st[j+1].B) j++; f[i][sl]=st[j].A*g[i]+st[j].B; tr[i][sl]=st[j].vt; } if(f[i][sl-1]>-1) { db A=g[i],B=f[i][sl-1]-g[i]*g[i]; while(top>=2 && giao({ A,B,i },st[top-1])<giao(st[top],st[top-1])) top--; st[++top]={ A,B,i }; } // cerr<<i<<" "<<sl-1<<" "<<top<<'\n'; // cerr<<f[i][sl]<<" "<<top<<" "<<i<<" "<<sl<<'\n'; } } cout<<f[n][k]<<'\n'; i=n; while(k>0) { d[i]=1; i=tr[i][k]; k--; } for(i=1;i<n;i++) if(d[i]==1) cout<<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...