#include <bits/stdc++.h>
using namespace std;
#define int int64_t
#define z(X, Y) (X = max(X, Y))
signed main() {
cin.tie(0)->sync_with_stdio(0);
int N; cin >> N;
int d[N]; for(int &i : d) cin >> i;
int dp[N][N] {}, ans {};
for(int i = 1; i < N; ++i) {
int s0 {}, s1 {}, k = i - 1, cnt {};
for(int j = i, f {}; j < N; ++j) {
for(; k >= 0 && s0 + d[k] < s1 + d[j]; --k)
if((s0 += d[k]) == s1) ++cnt, f = k;
s1 += d[j];
if(f > 0) z(dp[i][j], dp[f-1][i-1] + cnt);
z(ans, z(dp[i][j], dp[i][j-1]));
}
for(int j = 1; j <= i; ++j)
z(dp[j][i], dp[j-1][i]);
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
316 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 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 |
2 ms |
2260 KB |
Output is correct |
5 |
Correct |
2 ms |
2260 KB |
Output is correct |
6 |
Correct |
2 ms |
2260 KB |
Output is correct |
7 |
Correct |
3 ms |
2260 KB |
Output is correct |
8 |
Correct |
2 ms |
2260 KB |
Output is correct |
9 |
Correct |
3 ms |
2260 KB |
Output is correct |
10 |
Correct |
3 ms |
2240 KB |
Output is correct |
11 |
Correct |
3 ms |
2260 KB |
Output is correct |
12 |
Correct |
3 ms |
2260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
316 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
2260 KB |
Output is correct |
22 |
Correct |
2 ms |
2260 KB |
Output is correct |
23 |
Correct |
2 ms |
2260 KB |
Output is correct |
24 |
Correct |
2 ms |
2260 KB |
Output is correct |
25 |
Correct |
2 ms |
2260 KB |
Output is correct |
26 |
Correct |
2 ms |
2260 KB |
Output is correct |
27 |
Correct |
3 ms |
2260 KB |
Output is correct |
28 |
Correct |
2 ms |
2260 KB |
Output is correct |
29 |
Correct |
3 ms |
2260 KB |
Output is correct |
30 |
Correct |
3 ms |
2240 KB |
Output is correct |
31 |
Correct |
3 ms |
2260 KB |
Output is correct |
32 |
Correct |
3 ms |
2260 KB |
Output is correct |
33 |
Correct |
2 ms |
2240 KB |
Output is correct |
34 |
Correct |
2 ms |
2260 KB |
Output is correct |
35 |
Correct |
2 ms |
2260 KB |
Output is correct |
36 |
Correct |
2 ms |
2260 KB |
Output is correct |
37 |
Correct |
3 ms |
2260 KB |
Output is correct |
38 |
Correct |
2 ms |
2260 KB |
Output is correct |
39 |
Correct |
4 ms |
2260 KB |
Output is correct |
40 |
Correct |
3 ms |
2236 KB |
Output is correct |
41 |
Correct |
3 ms |
2260 KB |
Output is correct |
42 |
Correct |
2 ms |
2260 KB |
Output is correct |
43 |
Correct |
3 ms |
2260 KB |
Output is correct |
44 |
Correct |
3 ms |
2260 KB |
Output is correct |
45 |
Correct |
3 ms |
2244 KB |
Output is correct |
46 |
Correct |
2 ms |
2260 KB |
Output is correct |
47 |
Correct |
3 ms |
2260 KB |
Output is correct |
48 |
Correct |
2 ms |
2260 KB |
Output is correct |
49 |
Correct |
2 ms |
2260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
316 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
2260 KB |
Output is correct |
22 |
Correct |
2 ms |
2260 KB |
Output is correct |
23 |
Correct |
2 ms |
2260 KB |
Output is correct |
24 |
Correct |
2 ms |
2260 KB |
Output is correct |
25 |
Correct |
2 ms |
2260 KB |
Output is correct |
26 |
Correct |
2 ms |
2260 KB |
Output is correct |
27 |
Correct |
3 ms |
2260 KB |
Output is correct |
28 |
Correct |
2 ms |
2260 KB |
Output is correct |
29 |
Correct |
3 ms |
2260 KB |
Output is correct |
30 |
Correct |
3 ms |
2240 KB |
Output is correct |
31 |
Correct |
3 ms |
2260 KB |
Output is correct |
32 |
Correct |
3 ms |
2260 KB |
Output is correct |
33 |
Correct |
2 ms |
2240 KB |
Output is correct |
34 |
Correct |
2 ms |
2260 KB |
Output is correct |
35 |
Correct |
2 ms |
2260 KB |
Output is correct |
36 |
Correct |
2 ms |
2260 KB |
Output is correct |
37 |
Correct |
3 ms |
2260 KB |
Output is correct |
38 |
Correct |
2 ms |
2260 KB |
Output is correct |
39 |
Correct |
4 ms |
2260 KB |
Output is correct |
40 |
Correct |
3 ms |
2236 KB |
Output is correct |
41 |
Correct |
3 ms |
2260 KB |
Output is correct |
42 |
Correct |
2 ms |
2260 KB |
Output is correct |
43 |
Correct |
3 ms |
2260 KB |
Output is correct |
44 |
Correct |
3 ms |
2260 KB |
Output is correct |
45 |
Correct |
3 ms |
2244 KB |
Output is correct |
46 |
Correct |
2 ms |
2260 KB |
Output is correct |
47 |
Correct |
3 ms |
2260 KB |
Output is correct |
48 |
Correct |
2 ms |
2260 KB |
Output is correct |
49 |
Correct |
2 ms |
2260 KB |
Output is correct |
50 |
Correct |
252 ms |
195936 KB |
Output is correct |
51 |
Correct |
245 ms |
196048 KB |
Output is correct |
52 |
Correct |
275 ms |
195936 KB |
Output is correct |
53 |
Correct |
262 ms |
196104 KB |
Output is correct |
54 |
Correct |
241 ms |
195936 KB |
Output is correct |
55 |
Correct |
243 ms |
195960 KB |
Output is correct |
56 |
Correct |
265 ms |
196148 KB |
Output is correct |
57 |
Correct |
256 ms |
196028 KB |
Output is correct |
58 |
Correct |
272 ms |
196060 KB |
Output is correct |
59 |
Correct |
281 ms |
196028 KB |
Output is correct |
60 |
Correct |
284 ms |
195988 KB |
Output is correct |
61 |
Correct |
261 ms |
196028 KB |
Output is correct |
62 |
Correct |
258 ms |
196000 KB |
Output is correct |
63 |
Correct |
244 ms |
195976 KB |
Output is correct |
64 |
Correct |
255 ms |
196104 KB |
Output is correct |
65 |
Correct |
256 ms |
195928 KB |
Output is correct |
66 |
Correct |
252 ms |
196028 KB |
Output is correct |
67 |
Correct |
245 ms |
196188 KB |
Output is correct |
68 |
Correct |
241 ms |
195960 KB |
Output is correct |
69 |
Correct |
240 ms |
195988 KB |
Output is correct |
70 |
Correct |
270 ms |
196032 KB |
Output is correct |
71 |
Correct |
275 ms |
196032 KB |
Output is correct |
72 |
Correct |
268 ms |
196140 KB |
Output is correct |