# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
35141 | UncleGrandpa925 | Split the sequence (APIO14_sequence) | C++14 | 2000 ms | 84440 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.
/*input
5 4
1 2 3 4 5
*/
#include <bits/stdc++.h>
using namespace std;
#define sp ' '
#define endl '\n'
#define fi first
#define se second
#define mp make_pair
#define N 100005
#define bit(x,y) ((x>>y)&1LL)
#define na(x) (#x) << ":" << x
ostream& operator << (ostream &os, vector<int>&x) {
for (int i = 0; i < x.size(); i++) os << x[i] << sp;
return os;
}
ostream& operator << (ostream &os, pair<int, int> x) {
cout << x.fi << sp << x.se << sp;
return os;
}
ostream& operator << (ostream &os, vector<pair<int, int> >&x) {
for (int i = 0; i < x.size(); i++) os << x[i] << endl;
return os;
}
int n, m;
int a[N];
int sum[N];
long long dp[N][2];
int par[N][205];
vector<int> order;
signed main() {
#ifdef UncleGrandpa
freopen("1test.inp", "r", stdin);
#endif
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]), sum[i] = sum[i - 1] + a[i];
for (int i = 1; i <= n; i++) dp[i][0] = 0;
for (int p = 1; p <= m; p++) {
int c = p & 1;
for (int i = 0; i < N; i++) dp[i][c] = 0;
for (int i = 2; i <= n; i++) {
for (int j = 1; j < i; j++) {
if (dp[j][c ^ 1] + sum[j] * 1LL * (sum[i] - sum[j]) >= dp[i][c]) {
dp[i][c] = dp[j][c ^ 1] + sum[j] * 1LL * (sum[i] - sum[j]);
par[i][p] = j;
}
}
}
}
printf("%lld\n", dp[n][m & 1]);
pair<int, int> cur = mp(n, m);
while (cur.se >= 1) {
order.push_back(par[cur.fi][cur.se]);
cur.fi = par[cur.fi][cur.se]; cur.se--;
}
reverse(order.begin(), order.end());
// for (int i = 0; i < order.size(); i++) assert(order[i] != 0);
for (int i = 0; i < order.size(); i++) printf("%d ", order[i]);
}
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... |