Submission #676581

#TimeUsernameProblemLanguageResultExecution timeMemory
676581benjaminkleynSplit the sequence (APIO14_sequence)C++17
28 / 100
2083 ms2776 KiB
#pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("avx,avx2,fma") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; int N, K, a[100001]; ll pref[100001] = {0}; ll dp[2][100001] = {0}; int last_split[202][100001]; #define m(j) (pref[j]) #define c(j) (dp[0][j]-pref[j]*pref[N]) inline ll eval(const int &i, const ll &x) { return m(i) * x + c(i); } int main() { cin.tie(0)->sync_with_stdio(0); cin >> N >> K; for (int i = 1; i <= N; i++) { cin >> a[i]; pref[i] = pref[i-1] + a[i]; } for (int i = 0; i <= N; i++) dp[0][i] = pref[i] * (pref[N] - pref[i]); for (int k = 2; k <= K + 1; k++) { for (int i = k; i <= N; i++) { dp[1][i] = 0; for (int j = k - 1; j < i; j++) if (eval(j, pref[i]) > dp[1][i]) { dp[1][i] = eval(j, pref[i]); last_split[k][i] = j; } dp[1][i] += pref[i] * (pref[N] - pref[i]); } for (int i = 1; i <= N; i++) dp[0][i] = dp[1][i]; } cout << dp[0][N] << '\n'; int i = N; do { i = last_split[K+1][i]; cout << i << ' '; } while (--K); cout << '\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...