Submission #946239

#TimeUsernameProblemLanguageResultExecution timeMemory
946239KK_1729Split the sequence (APIO14_sequence)C++17
0 / 100
2050 ms33112 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define FOR(i,a,b) for (int i = (a); i < (b); ++i) #define pb push_back #define all(a) a.begin(), a.end() #define endl "\n" void printVector(vector<int> a){ for (auto x: a) cout << x << " "; cout << endl; } int max(int x, int y){ if (x > y) return x; else return y; } void solve(){ int n, k; cin >> n >> k; vector<int> a(n+1); FOR(i,0,n) cin >> a[i+1]; vector<int> prefix(n+1); FOR(i,1,n+1) prefix[i] = prefix[i-1]+a[i]; vector<vector<int>> dp(n+1, vector<int>(k+2)); vector<vector<int>> prev(n+1, vector<int>(k+2)); for (int j = 1; j <= k+1; ++j){ for (int i = 1; i <= n; ++i){ if (j > i) continue; for (int u = 0; u < i; u++){ if (dp[u][j-1]+(prefix[i]-prefix[u])*(prefix[n]-prefix[i]) >= dp[i][j]){ prev[i][j] = u; dp[i][j] = dp[u][j-1]+(prefix[i]-prefix[u])*(prefix[n]-prefix[i]); } } } } int u = n; int h = k+1; cout << dp[n][k+1] << endl; while (prev[u][h] != 0){ cout << prev[u][h] << " "; u = prev[u][h]; h--; } cout << endl; } int32_t main(){ ios::sync_with_stdio(false); cin.tie(0); // freopen("in.in", stdin) int t = 1; // cin >> t; while (t--) solve(); }
#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...