# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
155650 | HellAngel | Split the sequence (APIO14_sequence) | C++14 | 162 ms | 131076 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 int long long
using namespace std;
const int maxn = 1e5 + 7;
int n, k, dp[207][maxn], a[maxn], m, prv[207][maxn];
void Solve(int x)
{
int cur = x - 1;
for(int i = x; i <= n; i++)
{
while(cur + 1 < i && dp[x - 1][cur] + (a[i] - a[cur]) * a[cur] <= dp[x - 1][cur + 1] + (a[i] - a[cur + 1]) * a[cur + 1])
{
cur++;
}
dp[x][i] = dp[x - 1][cur] + (a[i] - a[cur]) * a[cur];
prv[x][i] = cur;
}
}
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
if(fopen("test.inp", "r")) freopen("test.inp", "r", stdin), freopen("test.out", "w", stdout);
cin >> n >> m;
for(int i = 1; i <= n; i++)
{
cin >> a[i];
a[i] += a[i - 1];
}
for(int j = 2; j <= m + 1; j++)
{
Solve(j);
}
cout << dp[m + 1][n] << '\n';
vector<int> ans;
for(int i = m; i >= 1; i--)
{
ans.push_back(prv[i + 1][n]);
n = prv[i + 1][n];
}
sort(ans.begin(), ans.end());
for(auto i: ans) cout << 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... |