Submission #900003

#TimeUsernameProblemLanguageResultExecution timeMemory
900003ByeWorldSplit the sequence (APIO14_sequence)C++14
71 / 100
517 ms131072 KiB
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,unroll-loops") #define bupol __builtin_popcount //#define int long long #define ll long long #define ld long double #define fi first #define se second #define pb push_back #define lf (id<<1) #define rg ((id<<1)|1) #define md ((l+r)>>1) using namespace std; const int MAXN = 1e5+5; const int MAXK = 205; const int LOG = 20; const int MOD = 1e9+7; const int SQRT = 520; const ll INF = 2e18; typedef pair<int,int> pii; typedef pair<int,pii> ipii; int n, k; int a[MAXN], pr[MAXN]; ll dp[MAXN][MAXK]; int ba[MAXN][MAXK]; signed main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin >> n >> k; for(int i=1; i<=n; i++){ cin >> a[i]; pr[i] = pr[i-1]+a[i]; } for(int i=0; i<=n+1; i++) for(int j=1; j<=k+1; j++) ba[i][j] = -1; for(int m=1; m<=k; m++){ int las = 1; for(int i=2; i<=n; i++){ dp[i][m] = -INF; for(int j=las; j<=i-1; j++){ if(ba[j][m-1] == -1) continue; // gk ada ke belakangnya if(dp[j][m-1] + 1ll * pr[j] * (pr[i]-pr[j]) > dp[i][m]){ // cek yg optimal potong dmn dp[i][m] = dp[j][m-1] + 1ll * pr[j] * (pr[i]-pr[j]); // cmn ngebuild sampe dp[i][i-1] ba[i][m] = j; } } las = ba[i][m]; //cout << dp[i][m] <<' ' << i << ' ' << m << '\n'; } } cout << dp[n][k] << '\n'; int nw = n; for(int i=k; i>=1; i--){ nw = ba[nw][i]; cout << nw << ' '; } 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...