# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
869321 | prohacker | Split the sequence (APIO14_sequence) | C++14 | 8 ms | 5468 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 ld long double
using namespace std;
const int N = 1010;
const int INF = INT_MAX;
const int mod = 1e9+7;
int n,m;
ll dp[N][210],ans;
int s[N],trace[N][210];
stack<int> st;
int get(int l, int r) {
return s[r] - s[l-1];
}
signed main()
{
if (fopen("task.inp", "r")) {
freopen("task.inp", "r", stdin);
freopen("task.out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for(int i = 1 ; i <= n ; i++) {
int x; cin >> x;
s[i] = s[i-1] + x;
}
// s[n+1] = s[n];
for(int k = 1 ; k <= m ; k++) {
for(int i = k ; i <= n ; i++) {
for(int j = i-1 ; j >= 0 ; j--) {
if(dp[j][k-1]+1LL*(s[i]-s[j])*(s[n]-s[i]) > dp[i][k]) {
dp[i][k] = dp[j][k-1]+1LL*(s[i]-s[j])*(s[n]-s[i]);
trace[i][k] = j;
}
}
}
}
int id;
ans = 0;
for(int i = 1 ; i <= n ; i++) {
if(dp[i][m] > ans) {
ans = dp[i][m];
id = i;
}
}
cout << ans << '\n';
while(m > 0) {
cout << id << " ";
id = trace[id][m];
if(id <= 0) {
cout << 1;
return 0;
}
// st.push(n);
m--;
}
// while(!st.empty()) {
// cout << st.top() << " ";
// st.pop();
// }
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... |