Submission #59062

#TimeUsernameProblemLanguageResultExecution timeMemory
59062zubecSplit the sequence (APIO14_sequence)C++14
28 / 100
252 ms2612 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; ll n, m, a[1100], pref[1100], dp[1100][210]; void rec(int n, int m){ if (m == 0) return; for (int i = n; i >= 1; i--){ if (dp[i][m-1] + (pref[n]-pref[i])*pref[i] == dp[n][m]){ rec(i, m-1); cout << i << ' '; return; } } } int main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin >> n >> m; for (int i = 1; i <= n; i++){ cin >> a[i]; pref[i] = pref[i-1] + a[i]; } for (int i = 0; i <= n; i++){ for (int j = 1; j <= m; j++) dp[i][j] = -1e15; } for (int ii = 1; ii <= m; ii++){ for (int i = 1; i <= n; i++){ for (int j = i; j >= 1; j--){ dp[i][ii] = max(dp[i][ii], dp[j][ii-1] + (pref[i]-pref[j])*(pref[j]) ); } } } cout << dp[n][m] << endl; rec(n, m); } /** 7 3 4 1 3 4 0 2 3 */
#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...