Submission #1189760

#TimeUsernameProblemLanguageResultExecution timeMemory
1189760vneduSplit the sequence (APIO14_sequence)C++17
22 / 100
32 ms2372 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; template<class T> bool maximize(T &a, const T &b){ return (a < b ? a = b, 1 : 0); } template<class T> bool minimize(T &a, const T &b){ return (a > b ? a = b, 1 : 0); } #define fi first #define se second #define pb push_back #define ii pair<int, int> #define all(x) x.begin(), x.end() #define TASK "nonsense" /// end of template /// const int N = 1e5 + 5; const int K = 200 + 5; int n,k,a[N],p[N]; namespace sub12 { const int N = 50+1; const ll inf = LLONG_MAX/2; bool check() { return (n<N); } ll dp[N][N][N]; ii trace[N][N][N]; void work(int tri, int i, int j) { if(i==j || tri==0) return; int tri1=trace[tri][i][j].fi; int pos=trace[tri][i][j].se; cout<<pos<<' '; work(tri1,i,pos); work(tri-1-tri1,pos+1,j); } void solve() { for(int tri=1;tri<=k;++tri) for(int i=1;i<=n;++i) for(int j=i;j<=n;++j) { dp[tri][i][j]=-inf; // bool dbg=(tri==3 && i==1 && j==7); for(int tri1=0;tri1<=tri-1;++tri1) { int tri2=tri-1-tri1; // cout<<tri<<' '<<tri1<<' '<<tri2<<'\n'; for(int pos=i;pos<j;++pos) { // if(dbg) cout<<tri<<' '<<tri1<<' '<<tri2<<' '<<pos<<' '<<dp[tri1][i][pos]<<' '<<dp[tri2][pos+1][j]<<' '<<(p[j]-p[pos])*1LL*(p[pos]-p[i-1])<<'\n'; if(maximize(dp[tri][i][j],dp[tri1][i][pos]+dp[tri2][pos+1][j]+(p[j]-p[pos])*1LL*(p[pos]-p[i-1]))) trace[tri][i][j]=make_pair(tri1,pos); } } // cout<<tri<<' '<<i<<' '<<j<<' '<<dp[tri][i][j]<<'\n'; } cout<<dp[k][1][n]<<'\n'; work(k,1,n); } } void solve() { cin>>n>>k; for(int i=1;i<=n;++i) cin>>a[i],p[i]=p[i-1]+a[i]; if(sub12::check()) return void(sub12::solve()); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen(TASK".inp","r",stdin); // freopen(TASK".out","w",stdout); int testcase=1; // cin>>testcase; while (testcase--) solve(); return 0; }
#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...