Submission #770751

#TimeUsernameProblemLanguageResultExecution timeMemory
770751OrazBSplit the sequence (APIO14_sequence)C++17
33 / 100
145 ms131072 KiB
#include <bits/stdc++.h> using namespace std; #define wr cout << "Continue debugging\n"; #define all(x) (x).begin(), (x).end() #define ll long long int #define pii pair <int, int> #define pb push_back #define ff first #define ss second const int N = 1005; const int MAXN = 1e5+5; int n, k; ll pref[N], dp[N][205]; vector<int> E[N][205]; int main () { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> k; for (int i = 1; i <= n; i++){ int x; cin >> x; pref[i] = pref[i-1]+x; } for (int i = 2; i <= n; i++){ for (int x = 1; x <= k; x++){ int pos = 0; for (int j = 1; j < i; j++){ ll cur = dp[j][x-1]+(pref[i]-pref[j])*pref[j]; if (dp[i][x] <= cur){ dp[i][x] = cur; pos = j; } } E[i][x].insert(E[i][x].end(), all(E[pos][x-1])); E[i][x].pb(pos); } } cout << dp[n][k] << '\n'; for (auto i : E[n][k]) cout << i << " "; }
#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...