# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
100228 | TadijaSebez | 수열 (APIO14_sequence) | C++11 | 453 ms | 82988 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>
using namespace std;
#define ll long long
#define mp make_pair
#define ldb long double
const int N=100050;
const int K=205;
const ll inf=1e18;
struct Line{ ll k,n;int id;Line(){}Line(ll a, ll b, int c):k(a),n(b),id(c){}};
int hsz,ptr=1;
ll dp[N],sum[N];
int go[K][N],a[N];
void Print(int n, int k)
{
if(k==0) return;
Print(go[k][n],k-1);
printf("%i ",go[k][n]);
}
int main()
{
int n,k;
scanf("%i %i",&n,&k);
for(int i=1;i<=n;++i) scanf("%i",&a[i]),sum[i]=sum[i-1]+a[i];
static Line Hull[N];
for(int j=1;j<=k;++j)
{
hsz=0;ptr=1;
Hull[++hsz]=Line(sum[j],dp[j]-sum[j]*sum[j],j);
for(int i=j+1;i<=n;++i)
{
Line l=Line(sum[i],dp[i]-sum[i]*sum[i],i);
while(ptr<hsz && Hull[ptr].k*sum[i]+Hull[ptr].n<=Hull[ptr+1].k*sum[i]+Hull[ptr+1].n) ++ptr;
dp[i]=Hull[ptr].k*sum[i]+Hull[ptr].n;
go[j][i]=Hull[ptr].id;
while(hsz>ptr && (l.n-Hull[hsz].n)*(Hull[hsz].k-Hull[hsz-1].k)>=(Hull[hsz].n-Hull[hsz-1].n)*(l.k-Hull[hsz].k)) --hsz;
Hull[++hsz]=l;
}
}
printf("%lld\n",dp[n]);
Print(n,k);
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... |