Submission #850113

#TimeUsernameProblemLanguageResultExecution timeMemory
850113treap_enjoyerSplit the sequence (APIO14_sequence)C++14
50 / 100
2035 ms24408 KiB
#include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> #pragma GCC optimize("Ofast,unroll-loops") #define ll long long #define all(x) x.begin(), x.end() using namespace std; using namespace __gnu_pbds; template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; const ll INF = 1e18; const int MAXN = 1e5 + 5; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); //ifstream cin("input.txt"); //ofstream cout("output.txt"); int n, k; cin >> n >> k; vector<ll> a(n + 1); for(int i = 1; i <= n; i++){ cin >> a[i]; } vector<vector<ll> > dp(k + 2, vector<ll>(n + 2, -INF)); vector<vector<int> > p(k + 2, vector<int>(n + 2, 0)); dp[0][0] = 0; vector<ll> pref(n + 2, 0); for(int i = 1; i <= n; i++){ pref[i] += pref[i - 1]; pref[i] += a[i]; } for(int i = 1; i <= k + 1; i++){ for(int j = 1; j <= n; j++){ for(int k = 0; k < j; k++){ if(dp[i][j] < dp[i - 1][k] + (pref[j] - pref[k]) * pref[k]){ dp[i][j] = dp[i - 1][k] + (pref[j] - pref[k]) * pref[k]; p[i][j] = k; } } } } vector<int> ans; int cur = n; for(int i = k; i > 0; i--){ ans.push_back(p[i + 1][cur]); cur = p[i + 1][cur]; } cout << dp[k + 1][n] << endl; reverse(all(ans)); for(auto i: ans){ cout << i << " "; } }
#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...