#include <bits/stdc++.h>
int main() {
int N;
std::cin >> N;
std::vector<int> D(N);
for (auto &e : D) {
std::cin >> e;
}
std::vector<std::vector<int>> dp(N, std::vector<int>(N));
for (int s = 1; s < N; ++s) {
std::vector<int> a, b;
for (int i = s; i < N; ++i) {
a.push_back(D[i]);
if (i != s) {
a[i - s] += a[i - s - 1];
}
}
for (int i = 0; i < s; ++i) {
b.push_back(D[s - i - 1]);
if (i != 0) {
b[i] += b[i - 1];
}
}
const int t = (int)a.size();
std::vector<int> points;
{
int r = 0;
for (int i = 0; i < t - 1; ++i) {
while (r != s and b[r] < a[i]) {
++r;
}
if (r < s - 1 and a[i] == b[r]) {
points.push_back(a[i]);
}
}
}
const int m = (int)points.size();
std::vector<int> max_c(s);
for (int i = 0; i < s; ++i) {
max_c[i] = dp[s - 1][i];
if (i != 0) {
max_c[i] = std::max(max_c[i], max_c[i - 1]);
}
}
int max_v = 0;
dp[s][s] = max_c[s - 1];
int r = 0, count_p = 0;
for (int i = 1; i < t; ++i) {
// dp[s + i][s]
while (count_p != m and points[count_p] <= a[i - 1]) {
while (r != s - 1 and b[r] < points[count_p]) {
max_v = std::max(max_v, dp[s - 1][s - r - 2] + count_p);
++r;
}
++count_p;
}
dp[s + i][s] = std::max(max_v, r == s - 1 ? 0 : (max_c[s - r - 2] + count_p));
/*
for (int j = 0; j < s - 1; ++j) {
int v = dp[s - 1][j];
auto itr = std::upper_bound(points.begin(), points.end(), std::min(a[i - 1], b[s - j - 2]));
dp[s + i][s] = std::max(dp[s + i][s], v + (int)(itr - points.begin()));
}
*/
}
}
std::cout << *std::max_element(dp[N - 1].begin(), dp[N - 1].end()) << std::endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
1340 KB |
Output is correct |
2 |
Correct |
4 ms |
1236 KB |
Output is correct |
3 |
Correct |
5 ms |
1336 KB |
Output is correct |
4 |
Correct |
4 ms |
1236 KB |
Output is correct |
5 |
Correct |
4 ms |
1336 KB |
Output is correct |
6 |
Correct |
5 ms |
1236 KB |
Output is correct |
7 |
Correct |
5 ms |
1236 KB |
Output is correct |
8 |
Correct |
5 ms |
1236 KB |
Output is correct |
9 |
Correct |
5 ms |
1236 KB |
Output is correct |
10 |
Correct |
4 ms |
1236 KB |
Output is correct |
11 |
Correct |
5 ms |
1236 KB |
Output is correct |
12 |
Correct |
4 ms |
1236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
4 ms |
1340 KB |
Output is correct |
22 |
Correct |
4 ms |
1236 KB |
Output is correct |
23 |
Correct |
5 ms |
1336 KB |
Output is correct |
24 |
Correct |
4 ms |
1236 KB |
Output is correct |
25 |
Correct |
4 ms |
1336 KB |
Output is correct |
26 |
Correct |
5 ms |
1236 KB |
Output is correct |
27 |
Correct |
5 ms |
1236 KB |
Output is correct |
28 |
Correct |
5 ms |
1236 KB |
Output is correct |
29 |
Correct |
5 ms |
1236 KB |
Output is correct |
30 |
Correct |
4 ms |
1236 KB |
Output is correct |
31 |
Correct |
5 ms |
1236 KB |
Output is correct |
32 |
Correct |
4 ms |
1236 KB |
Output is correct |
33 |
Correct |
4 ms |
1236 KB |
Output is correct |
34 |
Correct |
4 ms |
1236 KB |
Output is correct |
35 |
Correct |
4 ms |
1236 KB |
Output is correct |
36 |
Correct |
4 ms |
1344 KB |
Output is correct |
37 |
Correct |
5 ms |
1236 KB |
Output is correct |
38 |
Correct |
5 ms |
1236 KB |
Output is correct |
39 |
Correct |
5 ms |
1296 KB |
Output is correct |
40 |
Correct |
5 ms |
1236 KB |
Output is correct |
41 |
Correct |
4 ms |
1236 KB |
Output is correct |
42 |
Correct |
4 ms |
1236 KB |
Output is correct |
43 |
Correct |
4 ms |
1236 KB |
Output is correct |
44 |
Correct |
5 ms |
1340 KB |
Output is correct |
45 |
Correct |
5 ms |
1236 KB |
Output is correct |
46 |
Correct |
5 ms |
1236 KB |
Output is correct |
47 |
Correct |
5 ms |
1236 KB |
Output is correct |
48 |
Correct |
4 ms |
1236 KB |
Output is correct |
49 |
Correct |
4 ms |
1236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
4 ms |
1340 KB |
Output is correct |
22 |
Correct |
4 ms |
1236 KB |
Output is correct |
23 |
Correct |
5 ms |
1336 KB |
Output is correct |
24 |
Correct |
4 ms |
1236 KB |
Output is correct |
25 |
Correct |
4 ms |
1336 KB |
Output is correct |
26 |
Correct |
5 ms |
1236 KB |
Output is correct |
27 |
Correct |
5 ms |
1236 KB |
Output is correct |
28 |
Correct |
5 ms |
1236 KB |
Output is correct |
29 |
Correct |
5 ms |
1236 KB |
Output is correct |
30 |
Correct |
4 ms |
1236 KB |
Output is correct |
31 |
Correct |
5 ms |
1236 KB |
Output is correct |
32 |
Correct |
4 ms |
1236 KB |
Output is correct |
33 |
Correct |
4 ms |
1236 KB |
Output is correct |
34 |
Correct |
4 ms |
1236 KB |
Output is correct |
35 |
Correct |
4 ms |
1236 KB |
Output is correct |
36 |
Correct |
4 ms |
1344 KB |
Output is correct |
37 |
Correct |
5 ms |
1236 KB |
Output is correct |
38 |
Correct |
5 ms |
1236 KB |
Output is correct |
39 |
Correct |
5 ms |
1296 KB |
Output is correct |
40 |
Correct |
5 ms |
1236 KB |
Output is correct |
41 |
Correct |
4 ms |
1236 KB |
Output is correct |
42 |
Correct |
4 ms |
1236 KB |
Output is correct |
43 |
Correct |
4 ms |
1236 KB |
Output is correct |
44 |
Correct |
5 ms |
1340 KB |
Output is correct |
45 |
Correct |
5 ms |
1236 KB |
Output is correct |
46 |
Correct |
5 ms |
1236 KB |
Output is correct |
47 |
Correct |
5 ms |
1236 KB |
Output is correct |
48 |
Correct |
4 ms |
1236 KB |
Output is correct |
49 |
Correct |
4 ms |
1236 KB |
Output is correct |
50 |
Correct |
373 ms |
98524 KB |
Output is correct |
51 |
Correct |
356 ms |
98476 KB |
Output is correct |
52 |
Correct |
358 ms |
98460 KB |
Output is correct |
53 |
Correct |
381 ms |
98452 KB |
Output is correct |
54 |
Correct |
354 ms |
98524 KB |
Output is correct |
55 |
Correct |
358 ms |
98380 KB |
Output is correct |
56 |
Correct |
433 ms |
98472 KB |
Output is correct |
57 |
Correct |
434 ms |
98364 KB |
Output is correct |
58 |
Correct |
442 ms |
98452 KB |
Output is correct |
59 |
Correct |
414 ms |
98412 KB |
Output is correct |
60 |
Correct |
403 ms |
98460 KB |
Output is correct |
61 |
Correct |
378 ms |
98432 KB |
Output is correct |
62 |
Correct |
370 ms |
98484 KB |
Output is correct |
63 |
Correct |
367 ms |
98556 KB |
Output is correct |
64 |
Correct |
389 ms |
98572 KB |
Output is correct |
65 |
Correct |
370 ms |
98416 KB |
Output is correct |
66 |
Correct |
398 ms |
98476 KB |
Output is correct |
67 |
Correct |
376 ms |
98464 KB |
Output is correct |
68 |
Correct |
362 ms |
98712 KB |
Output is correct |
69 |
Correct |
349 ms |
98456 KB |
Output is correct |
70 |
Correct |
397 ms |
98456 KB |
Output is correct |
71 |
Correct |
385 ms |
98456 KB |
Output is correct |
72 |
Correct |
399 ms |
98576 KB |
Output is correct |