Submission #372314

#TimeUsernameProblemLanguageResultExecution timeMemory
372314Return_0Split the sequence (APIO14_sequence)C++17
100 / 100
1514 ms81068 KiB
#pragma GCC optimize("O2") #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1e5 + 3, K = 201; int par [K][N], n, k; ll dp [2][N], ps [N]; void solve (int t, int l, int r, int optl, int optr) { if (l > r) return; int m = (l + r) >> 1; ll bst = -1; par[t][m] = optl; for (int i = optl; i <= min(m - 1, optr); ++i) { ll p = dp[(t & 1) ^ 1][i] + ps[i] * (ps[m] - ps[i]); if (p > bst) { bst = p; par[t][m] = i; } } dp[t & 1][m] = bst; solve(t, l, m - 1, optl, par[t][m]); solve(t, m + 1, r, par[t][m], optr); } int main () { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin>> n >> k; for (int i = 1; i <= n; i++) cin>> ps[i], ps[i] += ps[i - 1]; for (int i = 1; i <= k; i++) solve(i, 1, n, 1, n); cout<< dp[k & 1][n] << '\n'; int cur = n; for (int i = k; i > 0; --i) cur = par[i][cur], cout<< cur << ' '; 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...