# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
370410 | daniel920712 | Bigger segments (IZhO19_segments) | C++14 | 310 ms | 93292 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 <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
long long all[500005];
long long DP[3005][3005];
long long big[3005][3005];
bool have[3005][3005]={0};
long long sum[500005]={0},N;
long long F(long long a,long long b)
{
long long i;
if(b==N) return 1;
if(have[a][b]) return DP[a][b];
have[a][b]=1;
for(i=b+1;i<=N;i++)
{
if(sum[i]-sum[b]>=sum[b]-sum[a]) DP[a][b]=max(DP[a][b],F(b,i)+1);
}
return DP[a][b];
}
int main()
{
long long i,j,k,ans=0;
scanf("%lld",&N);
for(i=1;i<=N;i++)
{
scanf("%lld",&all[i]);
sum[i]=all[i]+sum[i-1];
}
for(i=N;i>=0;i--)
{
big[i][N+1]=-1e18;
for(j=N;j>i;j--)
{
DP[i][j]=-1e18;
if(j==N) DP[i][j]=1;
else
{
k=lower_bound(sum+1,sum+N+1,2*sum[j]-sum[i])-sum;
DP[i][j]=big[j][k]+1;
//printf("%lld %lld %lld %lld\n",i,j,k,DP[i][j]);
}
big[i][j]=max(big[i][j+1],DP[i][j]);
}
}
for(i=1;i<=N;i++) ans=max(ans,DP[0][i]);
printf("%lld\n",ans);
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... |