Submission #499649

#TimeUsernameProblemLanguageResultExecution timeMemory
499649pragmatistSplit the sequence (APIO14_sequence)C++17
33 / 100
9 ms5452 KiB
#include <bits/stdc++.h> #define pb push_back #define sz(v) (int)v.size() #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() #define x first #define y second #define int long long #define nl "\n" using namespace std; typedef long long ll; typedef pair<long long, long long> pll; typedef pair <ll, ll> pii; const int N = (int)1e5 + 7; const int M = (int)7e6 + 7; const ll MOD = (ll)1e9 + 7; const int inf = (int)1e9 + 7; const ll INF = (ll)3e18 + 7; pii dir[] = {{-1, -1}, {1, 1}, {-1, 1}, {1, -1}}; int n, c, a[N], p[N], dp[201][201]; pii pr[201][201]; void solve() { cin >> n >> c; for(int i = 1; i <= n; ++i) { cin >> a[i]; p[i] = p[i - 1] + a[i]; } for(int i = 1; i < n; ++i) { for(int k = 1; k <= min(c, i); ++k) { for(int j = (k == 1 ? 0 : 1); j < i; ++j) { int cur = dp[j][k-1] + (p[i] - p[j]) * (p[n] - p[i]); if(cur >= dp[i][k]) { dp[i][k] = cur; pr[i][k] = {j, k - 1}; } } } } int ans = -1, s = 0; for(int i = 1; i <= n; ++i) { if(dp[i][c] > ans) { ans = dp[i][c]; s = i; } } vector<int> v; for(int t = c; t >= 1; --t) { v.pb(s); s = pr[s][t].x; } reverse(all(v)); cout << ans << nl; for(auto x : v) cout << x << ' '; } signed main() { ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0); int test = 1; //cin >> test; for(int i = 1; i <= test; ++i) { //cout << "Case " << i << ": "; solve(); } 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...