#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
long long arr[n],dp[n][n];
for(int i=0; i<n; i++) cin >> arr[i];
memset(dp,0,sizeof(dp));
long long ans=0;
for(int i=1; i<n; i++){
long long pref[n];
pref[0]=dp[0][i-1];
for(int j=1; j<i; j++) pref[j]=max(pref[j-1],dp[j][i-1]);
int c=i-1,be=0;
long long len=0,len2=0;
for(int j=i; j<n; j++){
len+=arr[j];
while(len2<len&&c>=0){
len2+=arr[c];
c--;
}
if(c>0) dp[i][j]=pref[c-1]+be;
if(len2==len) be++;
}
long long best=0;
len=0; len2=0; c=i-1; be=0;
for(int j=i; j<n; j++){
len+=arr[j];
while(len2<len&&c>=0){
len2+=arr[c];
best=max(best,dp[c][i-1]+be);
c--;
}
if(len==len2) be++;
dp[i][j]=max(dp[i][j],best);
ans=max(ans,dp[i][j]);
}
}
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2260 KB |
Output is correct |
2 |
Correct |
2 ms |
2260 KB |
Output is correct |
3 |
Correct |
2 ms |
2260 KB |
Output is correct |
4 |
Correct |
3 ms |
2276 KB |
Output is correct |
5 |
Correct |
3 ms |
2260 KB |
Output is correct |
6 |
Correct |
3 ms |
2260 KB |
Output is correct |
7 |
Incorrect |
2 ms |
2260 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |