# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
155646 | HellAngel | Split the sequence (APIO14_sequence) | C++14 | 15 ms | 3640 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;
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];
}
}
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];
}
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... |