Submission #310139

#TimeUsernameProblemLanguageResultExecution timeMemory
310139sofapudenSplit the sequence (APIO14_sequence)C++14
0 / 100
77 ms131076 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; vector<ll> v(100005); vector<vector<ll>> dp(2,vector<ll>(100005)), L(100005,vector<ll>(205)); ll k; void find(ll l, ll r, ll lb, ll rb, ll Z){ if(l > r)return; ll mid = (l+r)>>1; ll pos = lb, ma = -1; for(int i = lb; i < min(mid,rb+1); ++i){ if(ma < dp[0][i]+(v[mid]-v[i])*v[i]){ ma = dp[0][i]+(v[mid]-v[i])*v[i]; pos = i; } } dp[1][mid] = ma; L[mid][Z] = pos; find(l,mid-1,lb,pos,Z); find(mid+1,r,pos,rb,Z); } int main(){ int n; cin >> n >> k; for(int i = 0; i++ < n;){ cin >> v[i]; } if(n == 2){ cout << v[1]*v[2] << "\n"; cout << 1 << "\n"; } for(int i = 0; i++ < n;){ v[i]+=v[i-1]; } for(int i = 1; i<=k; ++i){ find(1,n,1,n,i); for(int j = 1; j <= n; ++j)dp[0][j] = dp[1][j]; } ll ans = 0; ll ind = 0; for(int i = 1; i <= n; ++i){ if(ans < dp[0][i]){ ind = i; ans = dp[0][i]; } } cout << ans << "\n"; while(k--){ cout << L[ind][k]+1 << " "; ind = L[ind][k]; } cout << "\n"; }
#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...