Submission #47889

#TimeUsernameProblemLanguageResultExecution timeMemory
47889square1001Split the sequence (APIO14_sequence)C++14
50 / 100
2070 ms2428 KiB
#include <iostream> #include <algorithm> using namespace std; const long long inf = 1LL << 60; int n, m, s[100009], p[209][100009]; long long dp[100009]; int main() { cin.tie(0); ios_base::sync_with_stdio(false); cin >> n >> m; for (int i = 0; i < n; i++) { cin >> s[i + 1]; s[i + 1] += s[i]; } fill(dp + 1, dp + n + 1, inf); for (int i = 0; i <= m; i++) { for (int j = n; j >= 0; j--) { dp[j] = inf; for (int k = 0; k < j; k++) { if (dp[j] > dp[k] - 2LL * s[k] * s[j]) { dp[j] = dp[k] - 2LL * s[k] * s[j]; p[i][j] = k; } } if(dp[j] != inf) dp[j] += 2LL * s[j] * s[j]; } } cout << (2LL * s[n] * s[n] - dp[n]) / 2 << '\n'; int pos = n; for (int i = m; i >= 1; i--) { pos = p[i][pos]; cout << pos << (i != 1 ? ' ' : '\n'); } 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...