# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
100221 | TadijaSebez | 수열 (APIO14_sequence) | C++11 | 2061 ms | 84472 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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){}pair<ll,int> Get(ll x){ return mp(k*x+n,id);}} Hull[N];
ldb sec(Line a, Line b){ return b.k==a.k?-1e18:(ldb)(a.n-b.n)/(b.k-a.k);}
int hsz,ptr=1;
ll dp[N],sum[N];
int go[N][K];
void Print(int n, int k)
{
if(k==0) return;
Print(go[n][k],k-1);
printf("%i ",n);
}
int main()
{
int n,k;
scanf("%i %i",&n,&k);k++;
for(int i=1;i<=n;i++) scanf("%lld",&sum[i]),sum[i]+=sum[i-1],dp[i]=-inf;
for(int j=1;j<=k;j++)
{
hsz=0;ptr=1;
int c=j&1,p=c^1;
Hull[++hsz]=Line(sum[j-1],dp[j-1]-sum[j-1]*sum[j-1],j-1);
for(int i=j;i<=n;i++)
{
Line l=Line(sum[i],dp[i]-sum[i]*sum[i],i);
while(ptr<hsz && Hull[ptr].Get(sum[i])<Hull[ptr+1].Get(sum[i])) ptr++;
dp[i]=Hull[ptr].k*sum[i]+Hull[ptr].n;
go[i][j]=Hull[ptr].id;
while(hsz>ptr && sec(Hull[hsz-1],Hull[hsz])>=sec(Hull[hsz],l)) hsz--;
Hull[++hsz]=l;
}
}
printf("%lld\n",dp[n]);
Print(go[n][k],k-1);
return 0;
}
컴파일 시 표준 에러 (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... |