Submission #226432

#TimeUsernameProblemLanguageResultExecution timeMemory
226432sevlllSplit the sequence (APIO14_sequence)C++14
0 / 100
484 ms131076 KiB
// #define _GLIBCXX_DEBUG #include <iostream> #include <iomanip> #include <cstdio> #include <cstdlib> #include <algorithm> #include <cmath> #include <vector> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <queue> #include <ctime> #include <cassert> #include <complex> #include <string> #include <cstring> #include <random> #include <queue> #include <bitset> #define int long long #define dbl long double #define pb push_back #define str string using namespace std; const int M = 998244353; int dp[100009][209]; int par[100009][209]; signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n, k; cin >> n >> k; vector<int> A(n + 1); for (int i = 1; i <= n; i++) cin >> A[n + 1 - i]; for (int i = 1; i <= n; i++) { for (int j = 1; j <= k; j++) { dp[i][j] = -1e18; } } vector<int> pref = A; for (int i = 1; i <= n; i++) pref[i] += pref[i - 1]; for (int t = 1; t <= k; t++) { for (int i = 1; i <= n; i++) { for (int j = 1; j < i; j++) { if (dp[i][t] < dp[j][t - 1] + pref[j] * (pref[i] - pref[j])) { par[i][t] = j; dp[i][t] = dp[j][t - 1] + pref[j] * (pref[i] - pref[j]); } } } } cout << dp[n][k] << '\n'; int i = n; int t = k; vector<int> ans; while (t--) { ans.pb(n - 1 - par[i][t]); i = par[i][t]; } for (auto p : ans) cout << p << ' '; }
#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...