Submission #130110

#TimeUsernameProblemLanguageResultExecution timeMemory
130110mlyean00Split the sequence (APIO14_sequence)C++14
50 / 100
2057 ms31912 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } vector<ll> pref(n + 1, 0); partial_sum(a.begin(), a.end(), pref.begin() + 1); ll dp[k + 1][n], parent[k + 1][n]; memset(dp, 0xff, sizeof(dp)); memset(parent, 0xff, sizeof(dp)); for (int j = 0; j < n; ++j) { dp[0][j] = 0; } for (int i = 1; i <= k; ++i) { for (int j = 0; j < n; ++j) { for (int h = i - 1; h < j; ++h) { ll t = dp[i - 1][h] + (pref[h + 1] - pref[0]) * (pref[j + 1] - pref[h + 1]); if (t >= dp[i][j]) { dp[i][j] = t; parent[i][j] = h; } } } } cout << dp[k][n - 1] << endl; int u = n - 1; for (int i = k; i > 0; --i) { u = parent[i][u]; cout << (u + 1) << ' '; } cout << endl; 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...