#include <bits/stdc++.h>
#define pb push_back
#define pf push_front
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define EPSILON 0.000001
#define CH (*s-'a')
using namespace std;
const ll NMAX = 5e2 + 5, INF = 1e18, MOD = 1e9 + 7, MMAX = 1e2 + 5, inf = 1e9;
ifstream fin("sufle.in");
ofstream fout("sufle.out");
int N,ans;
int v[NMAX],best[NMAX][NMAX],S[NMAX];
int main()
{
cin.tie ( 0 )->sync_with_stdio ( 0 );
cin.tie ( NULL );
cout.tie ( NULL );
cin>>N;
for(int i=1;i<=N;i++)
{
cin>>v[i];
S[i]=S[i-1]+v[i];
}
for(int i=2;i<=N;i++)
{
for(int j=i;j>=1;j--)
{
int ind=j-1;
int layer=0;
int sum=0;
for(int k=j;k<=i;k++)
{
sum+=v[k];
while(sum>layer&&ind>0)
{
layer+=v[ind];
ind--;
}
if(sum==layer&&k<i)best[i][j]++;
}
ind++;
if(layer>sum)
{
if(sum-v[i]<layer-v[ind+1])
{
ind++;
layer-=v[ind];
}
}
else if(layer<sum)
{
if(sum-v[i]>=layer)
{
if(j>1)best[i][j]=-1;
}
}
best[i][j]+=best[j-1][ind];
ans=max(ans,best[i][j]);
}
}
cout<<ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
45 ms |
1356 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |