이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
const int N=5e3;
const int PP=82e2;;
int tab[N+10];
int dp[N+10][N+10];
int pot;
int tree[2*PP+10];
int lazy[2*PP+10];
void add(int i,int l,int r,int ls,int rs,int c)
{
if(r<ls || rs<l)
return;
if(ls<=l && r<=rs)
{
lazy[i]+=c;
return;
}
int mid=(l+r)/2;
add(2*i,l,mid,ls,rs,c);
add(2*i+1,mid+1,r,ls,rs,c);
tree[i]=max(tree[2*i]+lazy[2*i],tree[2*i+1]+lazy[2*i+1]);
return;
}
int read()
{
return tree[1]+lazy[1];
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin>>n;
for(pot=1;pot<=n;pot*=2);
for(int i=1;i<=n;i++)
cin>>tab[i];
for(int j=1;j<n;j++)
{
for(int k=0;k<=2*pot;k++)
tree[k]=lazy[k]=0;
for(int k=0;k<j;k++)
tree[pot+k]=dp[j][k];
for(int k=pot-1;k>0;k--)
tree[k]=max(tree[2*k],tree[2*k+1]);
int it=j;
int s1=0,s2=tab[j];
for(int i=j+1;i<=n;i++)
{
while(it>0 && s2<s1)
{
it--;
s2+=tab[it];
}
if(s2==s1)
add(1,1,pot,0,it-1,1);
s1+=tab[i];
dp[i][j]=read();
//cerr<<i<<" "<<j<<" "<<dp[i][j]<<"\n";
}
}
int ans=0;
for(int j=1;j<n;j++)
ans=max(ans,dp[n][j]);
cout<<ans<<"\n";
return 0;
}
# | 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... |