Submission #874976

#TimeUsernameProblemLanguageResultExecution timeMemory
874976NintsiChkhaidzeSplit the sequence (APIO14_sequence)C++17
0 / 100
217 ms131072 KiB
#include <bits/stdc++.h> #define ll long long #define pb push_back #define s second #define f first #define int ll using namespace std; const int N = 1e5 + 3; int a[N],p[N],dp[N][203],lst[N][203]; signed main() { ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL); int n,k; cin>>n>>k; for (int i = 1; i <= n; i++){ cin >> a[i]; p[i] = p[i - 1] + a[i]; } for (int r = 2; r <= n + 1; r++) for (int kk = 1; kk <= k; kk++) dp[r][kk] = -1; for (int i = 2; i <= n; i++){ for (int j = 1; j <= k; j++){ if (dp[i - 1][j] > dp[i][j]){ dp[i][j] = dp[i - 1][j]; lst[i][j] = lst[i - 1][j]; } for (int l = 1; l < i; l++){ if (dp[l - 1][j - 1] == -1) continue; int s1 = p[n] - p[i - 1],s2 = p[i - 1] - p[l - 1]; int reward = s1*s2; int cur = dp[l][j - 1] + reward; if (cur > dp[i][j]){ dp[i][j] = cur; lst[i][j] = l; } } } } cout<<dp[n][k]<<endl; vector <int> ans; int id = n; for (int i = k; i >= 1; i--){ id = lst[id][i]; ans.pb(id); } for (int i = k - 1; i >= 0; i--) cout<<ans[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...