#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
using namespace std;
const int N = 3e3 + 7;
int n;
int a[N];
long long pre[N];
int dp[N][N];
int mx[N][N];
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i ++) {
cin >> a[i];
pre[i] = pre[i - 1] + a[i];
}
auto get = [&](int l, int r) -> long long {
return pre[r] - pre[l - 1];
};
for (int i = 1; i <= n; i ++) {
long long s = 0;
for (int j = i; j > 0; j --) {
s += a[j];
mx[i][j] = mx[i][j + 1];
if (j == 1) {
dp[i][j] = 1;
mx[i][j] = max(1, mx[i][j + 1]);
continue;
}
int lo = 1, hi = j - 1;
while (lo < hi) {
int mid = (lo + hi) >> 1;
if (get(mid, j - 1) <= s) {
hi = mid;
} else {
lo = mid + 1;
}
}
if (get(lo, j - 1) > s) {
continue;
}
if (mx[j - 1][lo] > 0) {
dp[i][j] = max(dp[i][j], mx[j - 1][lo] + 1);
}
mx[i][j] = max(dp[i][j], mx[i][j]);
}
}
cout << mx[n][1];
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
0 ms |
468 KB |
Output is correct |
6 |
Correct |
0 ms |
468 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
0 ms |
468 KB |
Output is correct |
14 |
Correct |
0 ms |
468 KB |
Output is correct |
15 |
Correct |
0 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
0 ms |
468 KB |
Output is correct |
6 |
Correct |
0 ms |
468 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
0 ms |
468 KB |
Output is correct |
14 |
Correct |
0 ms |
468 KB |
Output is correct |
15 |
Correct |
0 ms |
468 KB |
Output is correct |
16 |
Correct |
5 ms |
4820 KB |
Output is correct |
17 |
Correct |
6 ms |
5204 KB |
Output is correct |
18 |
Correct |
7 ms |
5204 KB |
Output is correct |
19 |
Correct |
5 ms |
5204 KB |
Output is correct |
20 |
Correct |
6 ms |
5140 KB |
Output is correct |
21 |
Correct |
7 ms |
5204 KB |
Output is correct |
22 |
Correct |
6 ms |
4052 KB |
Output is correct |
23 |
Correct |
4 ms |
3028 KB |
Output is correct |
24 |
Correct |
6 ms |
5204 KB |
Output is correct |
25 |
Correct |
5 ms |
5204 KB |
Output is correct |
26 |
Correct |
5 ms |
5204 KB |
Output is correct |
27 |
Correct |
5 ms |
5076 KB |
Output is correct |
28 |
Correct |
5 ms |
5204 KB |
Output is correct |
29 |
Correct |
5 ms |
5204 KB |
Output is correct |
30 |
Correct |
5 ms |
5204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
0 ms |
468 KB |
Output is correct |
6 |
Correct |
0 ms |
468 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
0 ms |
468 KB |
Output is correct |
14 |
Correct |
0 ms |
468 KB |
Output is correct |
15 |
Correct |
0 ms |
468 KB |
Output is correct |
16 |
Correct |
5 ms |
4820 KB |
Output is correct |
17 |
Correct |
6 ms |
5204 KB |
Output is correct |
18 |
Correct |
7 ms |
5204 KB |
Output is correct |
19 |
Correct |
5 ms |
5204 KB |
Output is correct |
20 |
Correct |
6 ms |
5140 KB |
Output is correct |
21 |
Correct |
7 ms |
5204 KB |
Output is correct |
22 |
Correct |
6 ms |
4052 KB |
Output is correct |
23 |
Correct |
4 ms |
3028 KB |
Output is correct |
24 |
Correct |
6 ms |
5204 KB |
Output is correct |
25 |
Correct |
5 ms |
5204 KB |
Output is correct |
26 |
Correct |
5 ms |
5204 KB |
Output is correct |
27 |
Correct |
5 ms |
5076 KB |
Output is correct |
28 |
Correct |
5 ms |
5204 KB |
Output is correct |
29 |
Correct |
5 ms |
5204 KB |
Output is correct |
30 |
Correct |
5 ms |
5204 KB |
Output is correct |
31 |
Correct |
172 ms |
39860 KB |
Output is correct |
32 |
Correct |
170 ms |
52808 KB |
Output is correct |
33 |
Correct |
172 ms |
55172 KB |
Output is correct |
34 |
Correct |
167 ms |
53380 KB |
Output is correct |
35 |
Correct |
222 ms |
55156 KB |
Output is correct |
36 |
Correct |
178 ms |
55232 KB |
Output is correct |
37 |
Correct |
129 ms |
43448 KB |
Output is correct |
38 |
Correct |
79 ms |
31656 KB |
Output is correct |
39 |
Correct |
170 ms |
55168 KB |
Output is correct |
40 |
Correct |
217 ms |
55204 KB |
Output is correct |
41 |
Correct |
154 ms |
55200 KB |
Output is correct |
42 |
Correct |
158 ms |
54136 KB |
Output is correct |
43 |
Correct |
187 ms |
52940 KB |
Output is correct |
44 |
Correct |
190 ms |
55344 KB |
Output is correct |
45 |
Correct |
167 ms |
55224 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
0 ms |
468 KB |
Output is correct |
6 |
Correct |
0 ms |
468 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
0 ms |
468 KB |
Output is correct |
14 |
Correct |
0 ms |
468 KB |
Output is correct |
15 |
Correct |
0 ms |
468 KB |
Output is correct |
16 |
Correct |
5 ms |
4820 KB |
Output is correct |
17 |
Correct |
6 ms |
5204 KB |
Output is correct |
18 |
Correct |
7 ms |
5204 KB |
Output is correct |
19 |
Correct |
5 ms |
5204 KB |
Output is correct |
20 |
Correct |
6 ms |
5140 KB |
Output is correct |
21 |
Correct |
7 ms |
5204 KB |
Output is correct |
22 |
Correct |
6 ms |
4052 KB |
Output is correct |
23 |
Correct |
4 ms |
3028 KB |
Output is correct |
24 |
Correct |
6 ms |
5204 KB |
Output is correct |
25 |
Correct |
5 ms |
5204 KB |
Output is correct |
26 |
Correct |
5 ms |
5204 KB |
Output is correct |
27 |
Correct |
5 ms |
5076 KB |
Output is correct |
28 |
Correct |
5 ms |
5204 KB |
Output is correct |
29 |
Correct |
5 ms |
5204 KB |
Output is correct |
30 |
Correct |
5 ms |
5204 KB |
Output is correct |
31 |
Correct |
172 ms |
39860 KB |
Output is correct |
32 |
Correct |
170 ms |
52808 KB |
Output is correct |
33 |
Correct |
172 ms |
55172 KB |
Output is correct |
34 |
Correct |
167 ms |
53380 KB |
Output is correct |
35 |
Correct |
222 ms |
55156 KB |
Output is correct |
36 |
Correct |
178 ms |
55232 KB |
Output is correct |
37 |
Correct |
129 ms |
43448 KB |
Output is correct |
38 |
Correct |
79 ms |
31656 KB |
Output is correct |
39 |
Correct |
170 ms |
55168 KB |
Output is correct |
40 |
Correct |
217 ms |
55204 KB |
Output is correct |
41 |
Correct |
154 ms |
55200 KB |
Output is correct |
42 |
Correct |
158 ms |
54136 KB |
Output is correct |
43 |
Correct |
187 ms |
52940 KB |
Output is correct |
44 |
Correct |
190 ms |
55344 KB |
Output is correct |
45 |
Correct |
167 ms |
55224 KB |
Output is correct |
46 |
Correct |
2 ms |
2388 KB |
Output is correct |
47 |
Incorrect |
92 ms |
27312 KB |
Output isn't correct |
48 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
0 ms |
468 KB |
Output is correct |
6 |
Correct |
0 ms |
468 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
0 ms |
468 KB |
Output is correct |
14 |
Correct |
0 ms |
468 KB |
Output is correct |
15 |
Correct |
0 ms |
468 KB |
Output is correct |
16 |
Correct |
5 ms |
4820 KB |
Output is correct |
17 |
Correct |
6 ms |
5204 KB |
Output is correct |
18 |
Correct |
7 ms |
5204 KB |
Output is correct |
19 |
Correct |
5 ms |
5204 KB |
Output is correct |
20 |
Correct |
6 ms |
5140 KB |
Output is correct |
21 |
Correct |
7 ms |
5204 KB |
Output is correct |
22 |
Correct |
6 ms |
4052 KB |
Output is correct |
23 |
Correct |
4 ms |
3028 KB |
Output is correct |
24 |
Correct |
6 ms |
5204 KB |
Output is correct |
25 |
Correct |
5 ms |
5204 KB |
Output is correct |
26 |
Correct |
5 ms |
5204 KB |
Output is correct |
27 |
Correct |
5 ms |
5076 KB |
Output is correct |
28 |
Correct |
5 ms |
5204 KB |
Output is correct |
29 |
Correct |
5 ms |
5204 KB |
Output is correct |
30 |
Correct |
5 ms |
5204 KB |
Output is correct |
31 |
Correct |
172 ms |
39860 KB |
Output is correct |
32 |
Correct |
170 ms |
52808 KB |
Output is correct |
33 |
Correct |
172 ms |
55172 KB |
Output is correct |
34 |
Correct |
167 ms |
53380 KB |
Output is correct |
35 |
Correct |
222 ms |
55156 KB |
Output is correct |
36 |
Correct |
178 ms |
55232 KB |
Output is correct |
37 |
Correct |
129 ms |
43448 KB |
Output is correct |
38 |
Correct |
79 ms |
31656 KB |
Output is correct |
39 |
Correct |
170 ms |
55168 KB |
Output is correct |
40 |
Correct |
217 ms |
55204 KB |
Output is correct |
41 |
Correct |
154 ms |
55200 KB |
Output is correct |
42 |
Correct |
158 ms |
54136 KB |
Output is correct |
43 |
Correct |
187 ms |
52940 KB |
Output is correct |
44 |
Correct |
190 ms |
55344 KB |
Output is correct |
45 |
Correct |
167 ms |
55224 KB |
Output is correct |
46 |
Correct |
2 ms |
2388 KB |
Output is correct |
47 |
Incorrect |
92 ms |
27312 KB |
Output isn't correct |
48 |
Halted |
0 ms |
0 KB |
- |