#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
724 KB |
Output is correct |
2 |
Correct |
1 ms |
724 KB |
Output is correct |
3 |
Correct |
1 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
724 KB |
Output is correct |
5 |
Correct |
1 ms |
688 KB |
Output is correct |
6 |
Correct |
1 ms |
724 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
1 ms |
724 KB |
Output is correct |
9 |
Correct |
1 ms |
692 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
724 KB |
Output is correct |
2 |
Correct |
1 ms |
724 KB |
Output is correct |
3 |
Correct |
1 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
724 KB |
Output is correct |
5 |
Correct |
1 ms |
688 KB |
Output is correct |
6 |
Correct |
1 ms |
724 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
1 ms |
724 KB |
Output is correct |
9 |
Correct |
1 ms |
692 KB |
Output is correct |
10 |
Correct |
4 ms |
6996 KB |
Output is correct |
11 |
Correct |
4 ms |
6996 KB |
Output is correct |
12 |
Correct |
4 ms |
6960 KB |
Output is correct |
13 |
Correct |
4 ms |
6996 KB |
Output is correct |
14 |
Correct |
3 ms |
6996 KB |
Output is correct |
15 |
Correct |
4 ms |
6996 KB |
Output is correct |
16 |
Correct |
4 ms |
6996 KB |
Output is correct |
17 |
Correct |
3 ms |
6996 KB |
Output is correct |
18 |
Correct |
4 ms |
6996 KB |
Output is correct |
19 |
Correct |
4 ms |
6932 KB |
Output is correct |
20 |
Correct |
4 ms |
6996 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
220 ms |
249816 KB |
Output is correct |
2 |
Correct |
215 ms |
249788 KB |
Output is correct |
3 |
Correct |
229 ms |
249800 KB |
Output is correct |
4 |
Correct |
213 ms |
249840 KB |
Output is correct |
5 |
Correct |
224 ms |
249844 KB |
Output is correct |
6 |
Correct |
268 ms |
249724 KB |
Output is correct |
7 |
Correct |
276 ms |
249768 KB |
Output is correct |
8 |
Correct |
287 ms |
249728 KB |
Output is correct |
9 |
Correct |
277 ms |
249792 KB |
Output is correct |
10 |
Correct |
234 ms |
249780 KB |
Output is correct |
11 |
Correct |
252 ms |
249776 KB |
Output is correct |
12 |
Correct |
237 ms |
249796 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
724 KB |
Output is correct |
2 |
Correct |
1 ms |
724 KB |
Output is correct |
3 |
Correct |
1 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
724 KB |
Output is correct |
5 |
Correct |
1 ms |
688 KB |
Output is correct |
6 |
Correct |
1 ms |
724 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
1 ms |
724 KB |
Output is correct |
9 |
Correct |
1 ms |
692 KB |
Output is correct |
10 |
Correct |
4 ms |
6996 KB |
Output is correct |
11 |
Correct |
4 ms |
6996 KB |
Output is correct |
12 |
Correct |
4 ms |
6960 KB |
Output is correct |
13 |
Correct |
4 ms |
6996 KB |
Output is correct |
14 |
Correct |
3 ms |
6996 KB |
Output is correct |
15 |
Correct |
4 ms |
6996 KB |
Output is correct |
16 |
Correct |
4 ms |
6996 KB |
Output is correct |
17 |
Correct |
3 ms |
6996 KB |
Output is correct |
18 |
Correct |
4 ms |
6996 KB |
Output is correct |
19 |
Correct |
4 ms |
6932 KB |
Output is correct |
20 |
Correct |
4 ms |
6996 KB |
Output is correct |
21 |
Correct |
220 ms |
249816 KB |
Output is correct |
22 |
Correct |
215 ms |
249788 KB |
Output is correct |
23 |
Correct |
229 ms |
249800 KB |
Output is correct |
24 |
Correct |
213 ms |
249840 KB |
Output is correct |
25 |
Correct |
224 ms |
249844 KB |
Output is correct |
26 |
Correct |
268 ms |
249724 KB |
Output is correct |
27 |
Correct |
276 ms |
249768 KB |
Output is correct |
28 |
Correct |
287 ms |
249728 KB |
Output is correct |
29 |
Correct |
277 ms |
249792 KB |
Output is correct |
30 |
Correct |
234 ms |
249780 KB |
Output is correct |
31 |
Correct |
252 ms |
249776 KB |
Output is correct |
32 |
Correct |
237 ms |
249796 KB |
Output is correct |
33 |
Correct |
234 ms |
249844 KB |
Output is correct |
34 |
Correct |
231 ms |
249832 KB |
Output is correct |
35 |
Correct |
244 ms |
249768 KB |
Output is correct |
36 |
Correct |
244 ms |
249804 KB |
Output is correct |
37 |
Correct |
289 ms |
249804 KB |
Output is correct |
38 |
Correct |
301 ms |
249740 KB |
Output is correct |
39 |
Correct |
311 ms |
249848 KB |
Output is correct |
40 |
Correct |
313 ms |
249776 KB |
Output is correct |
41 |
Correct |
288 ms |
249780 KB |
Output is correct |
42 |
Correct |
315 ms |
249892 KB |
Output is correct |
43 |
Correct |
291 ms |
249768 KB |
Output is correct |
44 |
Correct |
316 ms |
249804 KB |
Output is correct |
45 |
Correct |
282 ms |
249824 KB |
Output is correct |
46 |
Correct |
290 ms |
249836 KB |
Output is correct |
47 |
Correct |
302 ms |
249824 KB |
Output is correct |
48 |
Correct |
299 ms |
249996 KB |
Output is correct |
49 |
Correct |
274 ms |
249796 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
724 KB |
Output is correct |
2 |
Correct |
1 ms |
724 KB |
Output is correct |
3 |
Correct |
1 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
724 KB |
Output is correct |
5 |
Correct |
1 ms |
688 KB |
Output is correct |
6 |
Correct |
1 ms |
724 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
1 ms |
724 KB |
Output is correct |
9 |
Correct |
1 ms |
692 KB |
Output is correct |
10 |
Correct |
4 ms |
6996 KB |
Output is correct |
11 |
Correct |
4 ms |
6996 KB |
Output is correct |
12 |
Correct |
4 ms |
6960 KB |
Output is correct |
13 |
Correct |
4 ms |
6996 KB |
Output is correct |
14 |
Correct |
3 ms |
6996 KB |
Output is correct |
15 |
Correct |
4 ms |
6996 KB |
Output is correct |
16 |
Correct |
4 ms |
6996 KB |
Output is correct |
17 |
Correct |
3 ms |
6996 KB |
Output is correct |
18 |
Correct |
4 ms |
6996 KB |
Output is correct |
19 |
Correct |
4 ms |
6932 KB |
Output is correct |
20 |
Correct |
4 ms |
6996 KB |
Output is correct |
21 |
Correct |
220 ms |
249816 KB |
Output is correct |
22 |
Correct |
215 ms |
249788 KB |
Output is correct |
23 |
Correct |
229 ms |
249800 KB |
Output is correct |
24 |
Correct |
213 ms |
249840 KB |
Output is correct |
25 |
Correct |
224 ms |
249844 KB |
Output is correct |
26 |
Correct |
268 ms |
249724 KB |
Output is correct |
27 |
Correct |
276 ms |
249768 KB |
Output is correct |
28 |
Correct |
287 ms |
249728 KB |
Output is correct |
29 |
Correct |
277 ms |
249792 KB |
Output is correct |
30 |
Correct |
234 ms |
249780 KB |
Output is correct |
31 |
Correct |
252 ms |
249776 KB |
Output is correct |
32 |
Correct |
237 ms |
249796 KB |
Output is correct |
33 |
Correct |
234 ms |
249844 KB |
Output is correct |
34 |
Correct |
231 ms |
249832 KB |
Output is correct |
35 |
Correct |
244 ms |
249768 KB |
Output is correct |
36 |
Correct |
244 ms |
249804 KB |
Output is correct |
37 |
Correct |
289 ms |
249804 KB |
Output is correct |
38 |
Correct |
301 ms |
249740 KB |
Output is correct |
39 |
Correct |
311 ms |
249848 KB |
Output is correct |
40 |
Correct |
313 ms |
249776 KB |
Output is correct |
41 |
Correct |
288 ms |
249780 KB |
Output is correct |
42 |
Correct |
315 ms |
249892 KB |
Output is correct |
43 |
Correct |
291 ms |
249768 KB |
Output is correct |
44 |
Correct |
316 ms |
249804 KB |
Output is correct |
45 |
Correct |
282 ms |
249824 KB |
Output is correct |
46 |
Correct |
290 ms |
249836 KB |
Output is correct |
47 |
Correct |
302 ms |
249824 KB |
Output is correct |
48 |
Correct |
299 ms |
249996 KB |
Output is correct |
49 |
Correct |
274 ms |
249796 KB |
Output is correct |
50 |
Runtime error |
487 ms |
514080 KB |
Execution killed with signal 11 |
51 |
Halted |
0 ms |
0 KB |
- |