제출 #724781

#제출 시각아이디문제언어결과실행 시간메모리
724781colossal_pepe수열 (APIO14_sequence)C++17
39 / 100
202 ms3552 KiB
#include <iostream> #include <vector> using namespace std; using ll = long long; const int N = 1000; const int K = 200; int n, k; ll a[N + 5], pfx_sum[N + 5]; pair<ll, int> dp[K + 5][N + 5]; ll score(int i, int j) { return pfx_sum[i] * (pfx_sum[n] - pfx_sum[j]); } pair<ll, vector<int>> retrieve() { ll x = 0; vector<int> v = {-1}; for (int i = 1; i <= n; i++) { if (dp[k][i].first > x) { x = dp[k][i].first; v.back() = i; } } for (int i = k; i >= 2; i--) { v.push_back(dp[i][v.back()].second); } return {x, v}; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> k; if (n > N) exit(0); a[0] = pfx_sum[0] = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; pfx_sum[i] = a[i] + pfx_sum[i - 1]; } for (int i = 1; i <= n; i++) { dp[1][i] = {score(i, i), -1}; for (int s = 2; s <= k; s++) { dp[s][i] = {-1, -1}; for (int j = 1; j < i; j++) { if (dp[s - 1][j].first == -1) continue; dp[s][i] = max(dp[s][i], {score(i, i) - score(j, i) + dp[s - 1][j].first, j}); } } } pair<ll, vector<int>> ans = retrieve(); cout << ans.first << '\n'; for (int i : ans.second) { cout << i << ' '; } 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...