이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int n,v[5005];
int dp[505][505][505],mn[505][505];
int main()
{
cin>>n;
for(int i=1; i<=n; i++) cin>>v[i];
int ans=0;
for(int i=2; i<=n; i++)
{
for(int j=i-1; j>=1; j--)
{
int st=j+1,dr=j;
long long a=v[st],b=v[dr];
int nr=0;
dp[i][j][j-1]=mn[j][j-1];
mn[i][j]=dp[i][j][j-1];
while( st<=i&&dr>=1 )
{
if(st==i&&dr==1) break;
if(st==i) dr--,b+=v[dr];
else if(dr==1) st++,a+=v[st];
else
{
if(a==b) nr++,st++,dr--,a+=v[st],b+=v[dr];
else if(a<b) st++,a+=v[st];
else dr--,b+=v[dr];
}
dp[i][j][dr-1]=max(dp[i][j][dr-1],nr+mn[j][dr-1]);
mn[i][j]=max(mn[i][j],dp[i][j][dr-1]);
}
ans=max(ans,mn[i][j]);
}
}
cout<<ans;
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... |