# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
932213 | Xiaoyang | Split the sequence (APIO14_sequence) | C++17 | 49 ms | 85076 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<stdio.h>
int n, k, a[100010], sl[100010][210], j;
long long d[100010], dd[100010], s[100010];
void get_l(int st, int ed, int left, int right)
{
int i, q, p;
long long m=9e19, x;
if(left > right) return;
p=(left + right)/2;
if(st == ed)
{
for(i = left; i<=right; ++i) sl[i][j]=st;
return;
}
for(i = st; i <= ed; ++i)
{
x=d[i] + (s[p] - s[i])*(s[p] - s[i]);
if (m > x){ m = x; q = i; }
}
sl[p][j]=q;
get_l(st, q, left, p-1);
get_l(q, ed, p + 1, right);
return;
}
void back(int x, int dep){
if (dep > 1)
{
back(sl[x][dep], dep - 1);
printf("%d", sl[x][dep]);
}
return;
}
int main()
{
int i, l;
scanf("%d%d", &n, &k);
for(i=1; i<=n; ++i) scanf("%d", &a[i]);
for(i=1; i<=n; ++i) s[i]=s[i-1]+a[i];
for(i=1; i<=n; ++i) d[i]=s[i]*s[i];
for(j=2; j<=k+1; ++j)
{
//
get_l(j - 1, n-(k + 1 - j), j, n);
for(i=j; i<=n; ++i)
{
l=sl[i][j];
dd[i]=d[l] + (s[i] - s[l])*(s[i] - s[l]);
}
for(i = j; i <= n; ++i) d[i]=dd[i];
}
printf("%lld\n", (s[n] * s[n] - d[n])/2);
back(n, k + 1);
}
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... |