# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
569014 | Ronin13 | Split the sequence (APIO14_sequence) | C++14 | 2086 ms | 131072 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define ull unsigned ll
#define pb push_back
#define epb emplace_back
#define pii pair<int,int>
#define pll pair<ll,ll>
using namespace std;
ll dp[100001][201];
ll p[100001][201];
const ll linf = 1e18 + 1;
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
int n; cin >> n;
int k; cin >> k;
ll pref[n + 1];
ll a[n + 1];
for(int i = 1; i <= n; i++){
cin >> a[i];
}
for(int i = 0; i <= n; i++){
for(int j = 0; j <= k; j++) dp[i][j] = -linf;
}
dp[0][0] = 0;
pref[0] = 0;
for(int i = 1; i <= n; i++) pref[i] = pref[i - 1] + a[i];
for(int i = 1; i <= n; i++){
for(int j = 0; j < k; j++){
for(int l = 0; l < i; l++){
ll val = dp[l][j] + (pref[i] - pref[l]) * (pref[n] - pref[i]);
if(dp[i][j + 1] < val){
dp[i][j + 1] = val;
p[i][j + 1] = l;
}
}
}
}
ll ans = -1;
ll mxi;
for(int i = 1; i <= n; i++){
if(ans < dp[i][k]) ans = dp[i][k], mxi = i;
}
cout << ans << "\n";
int cnt = k;
vector <int> vec;
while(cnt){
vec.pb(mxi);
mxi = p[mxi][cnt];
cnt--;
}
reverse(vec.begin(), vec.end());
for(auto to : vec) cout << to << ' ';
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |