#include <iostream>
#include <unordered_map>
#include <algorithm>
#include <set>
#include <string>
#include <vector>
#include <random>
#include <deque>
using namespace std;
mt19937 rng(420691273);
#define ll long long
const int MX = 5e3 + 5;
int n, v[MX], dp[MX][MX];
int main(){
cin.tie(0) -> sync_with_stdio(0);
cin >> n;
for(int i = 0; i < n; i ++) cin >> v[i];
for(int ps = 0; ps < n; ps ++){
for(int l = 1; l <= ps; l ++)
dp[l][ps] = max(dp[l][ps], dp[l - 1][ps]);
int up = 0, dn = 0, cnt = -1;
for(int l = ps, r = ps + 1; l >= 0 && r < n;){
if(up == dn){
cnt ++;
dp[ps + 1][r] = max(dp[ps + 1][r], dp[l][ps] + cnt);
dn += v[l --]; up += v[r ++];
}else if(up < dn)
up += v[r ++];
else if(up > dn)
dn += v[l --];
}
for(int r = ps + 1; r < n; r ++)
dp[ps + 1][r] = max(dp[ps + 1][r], dp[ps + 1][r - 1]);
}
int ans = 0;
for(int l = 0; l < n; l ++)
ans = max(ans, dp[l][n - 1]);
cout << ans << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
588 KB |
Output is correct |
11 |
Correct |
1 ms |
584 KB |
Output is correct |
12 |
Correct |
1 ms |
588 KB |
Output is correct |
13 |
Correct |
1 ms |
584 KB |
Output is correct |
14 |
Correct |
1 ms |
588 KB |
Output is correct |
15 |
Correct |
1 ms |
640 KB |
Output is correct |
16 |
Correct |
1 ms |
588 KB |
Output is correct |
17 |
Correct |
1 ms |
588 KB |
Output is correct |
18 |
Correct |
1 ms |
580 KB |
Output is correct |
19 |
Correct |
1 ms |
588 KB |
Output is correct |
20 |
Correct |
1 ms |
584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2764 KB |
Output is correct |
2 |
Correct |
4 ms |
2764 KB |
Output is correct |
3 |
Correct |
4 ms |
2764 KB |
Output is correct |
4 |
Correct |
3 ms |
2764 KB |
Output is correct |
5 |
Correct |
4 ms |
2764 KB |
Output is correct |
6 |
Correct |
5 ms |
2756 KB |
Output is correct |
7 |
Correct |
4 ms |
2764 KB |
Output is correct |
8 |
Correct |
4 ms |
2764 KB |
Output is correct |
9 |
Correct |
4 ms |
2764 KB |
Output is correct |
10 |
Correct |
4 ms |
2764 KB |
Output is correct |
11 |
Correct |
3 ms |
2764 KB |
Output is correct |
12 |
Correct |
3 ms |
2740 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
588 KB |
Output is correct |
11 |
Correct |
1 ms |
584 KB |
Output is correct |
12 |
Correct |
1 ms |
588 KB |
Output is correct |
13 |
Correct |
1 ms |
584 KB |
Output is correct |
14 |
Correct |
1 ms |
588 KB |
Output is correct |
15 |
Correct |
1 ms |
640 KB |
Output is correct |
16 |
Correct |
1 ms |
588 KB |
Output is correct |
17 |
Correct |
1 ms |
588 KB |
Output is correct |
18 |
Correct |
1 ms |
580 KB |
Output is correct |
19 |
Correct |
1 ms |
588 KB |
Output is correct |
20 |
Correct |
1 ms |
584 KB |
Output is correct |
21 |
Correct |
3 ms |
2764 KB |
Output is correct |
22 |
Correct |
4 ms |
2764 KB |
Output is correct |
23 |
Correct |
4 ms |
2764 KB |
Output is correct |
24 |
Correct |
3 ms |
2764 KB |
Output is correct |
25 |
Correct |
4 ms |
2764 KB |
Output is correct |
26 |
Correct |
5 ms |
2756 KB |
Output is correct |
27 |
Correct |
4 ms |
2764 KB |
Output is correct |
28 |
Correct |
4 ms |
2764 KB |
Output is correct |
29 |
Correct |
4 ms |
2764 KB |
Output is correct |
30 |
Correct |
4 ms |
2764 KB |
Output is correct |
31 |
Correct |
3 ms |
2764 KB |
Output is correct |
32 |
Correct |
3 ms |
2740 KB |
Output is correct |
33 |
Correct |
3 ms |
2764 KB |
Output is correct |
34 |
Correct |
4 ms |
2764 KB |
Output is correct |
35 |
Correct |
4 ms |
2764 KB |
Output is correct |
36 |
Correct |
5 ms |
2764 KB |
Output is correct |
37 |
Correct |
4 ms |
2756 KB |
Output is correct |
38 |
Correct |
4 ms |
2764 KB |
Output is correct |
39 |
Correct |
5 ms |
2736 KB |
Output is correct |
40 |
Correct |
4 ms |
2764 KB |
Output is correct |
41 |
Correct |
4 ms |
2764 KB |
Output is correct |
42 |
Correct |
4 ms |
2764 KB |
Output is correct |
43 |
Correct |
4 ms |
2756 KB |
Output is correct |
44 |
Correct |
4 ms |
2764 KB |
Output is correct |
45 |
Correct |
4 ms |
2764 KB |
Output is correct |
46 |
Correct |
3 ms |
2772 KB |
Output is correct |
47 |
Correct |
4 ms |
2764 KB |
Output is correct |
48 |
Correct |
4 ms |
2760 KB |
Output is correct |
49 |
Correct |
5 ms |
2764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
588 KB |
Output is correct |
11 |
Correct |
1 ms |
584 KB |
Output is correct |
12 |
Correct |
1 ms |
588 KB |
Output is correct |
13 |
Correct |
1 ms |
584 KB |
Output is correct |
14 |
Correct |
1 ms |
588 KB |
Output is correct |
15 |
Correct |
1 ms |
640 KB |
Output is correct |
16 |
Correct |
1 ms |
588 KB |
Output is correct |
17 |
Correct |
1 ms |
588 KB |
Output is correct |
18 |
Correct |
1 ms |
580 KB |
Output is correct |
19 |
Correct |
1 ms |
588 KB |
Output is correct |
20 |
Correct |
1 ms |
584 KB |
Output is correct |
21 |
Correct |
3 ms |
2764 KB |
Output is correct |
22 |
Correct |
4 ms |
2764 KB |
Output is correct |
23 |
Correct |
4 ms |
2764 KB |
Output is correct |
24 |
Correct |
3 ms |
2764 KB |
Output is correct |
25 |
Correct |
4 ms |
2764 KB |
Output is correct |
26 |
Correct |
5 ms |
2756 KB |
Output is correct |
27 |
Correct |
4 ms |
2764 KB |
Output is correct |
28 |
Correct |
4 ms |
2764 KB |
Output is correct |
29 |
Correct |
4 ms |
2764 KB |
Output is correct |
30 |
Correct |
4 ms |
2764 KB |
Output is correct |
31 |
Correct |
3 ms |
2764 KB |
Output is correct |
32 |
Correct |
3 ms |
2740 KB |
Output is correct |
33 |
Correct |
3 ms |
2764 KB |
Output is correct |
34 |
Correct |
4 ms |
2764 KB |
Output is correct |
35 |
Correct |
4 ms |
2764 KB |
Output is correct |
36 |
Correct |
5 ms |
2764 KB |
Output is correct |
37 |
Correct |
4 ms |
2756 KB |
Output is correct |
38 |
Correct |
4 ms |
2764 KB |
Output is correct |
39 |
Correct |
5 ms |
2736 KB |
Output is correct |
40 |
Correct |
4 ms |
2764 KB |
Output is correct |
41 |
Correct |
4 ms |
2764 KB |
Output is correct |
42 |
Correct |
4 ms |
2764 KB |
Output is correct |
43 |
Correct |
4 ms |
2756 KB |
Output is correct |
44 |
Correct |
4 ms |
2764 KB |
Output is correct |
45 |
Correct |
4 ms |
2764 KB |
Output is correct |
46 |
Correct |
3 ms |
2772 KB |
Output is correct |
47 |
Correct |
4 ms |
2764 KB |
Output is correct |
48 |
Correct |
4 ms |
2760 KB |
Output is correct |
49 |
Correct |
5 ms |
2764 KB |
Output is correct |
50 |
Correct |
249 ms |
67244 KB |
Output is correct |
51 |
Correct |
234 ms |
67184 KB |
Output is correct |
52 |
Correct |
252 ms |
67216 KB |
Output is correct |
53 |
Correct |
240 ms |
67260 KB |
Output is correct |
54 |
Correct |
252 ms |
67232 KB |
Output is correct |
55 |
Correct |
254 ms |
67268 KB |
Output is correct |
56 |
Correct |
296 ms |
67208 KB |
Output is correct |
57 |
Correct |
276 ms |
67376 KB |
Output is correct |
58 |
Correct |
273 ms |
67196 KB |
Output is correct |
59 |
Correct |
281 ms |
67180 KB |
Output is correct |
60 |
Correct |
282 ms |
67268 KB |
Output is correct |
61 |
Correct |
253 ms |
67232 KB |
Output is correct |
62 |
Correct |
248 ms |
67184 KB |
Output is correct |
63 |
Correct |
240 ms |
67220 KB |
Output is correct |
64 |
Correct |
249 ms |
67280 KB |
Output is correct |
65 |
Correct |
242 ms |
67296 KB |
Output is correct |
66 |
Correct |
251 ms |
67228 KB |
Output is correct |
67 |
Correct |
229 ms |
67308 KB |
Output is correct |
68 |
Correct |
252 ms |
67276 KB |
Output is correct |
69 |
Correct |
237 ms |
67268 KB |
Output is correct |
70 |
Correct |
270 ms |
67236 KB |
Output is correct |
71 |
Correct |
284 ms |
67312 KB |
Output is correct |
72 |
Correct |
270 ms |
67332 KB |
Output is correct |