#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;
std::vector<bool> is_p_a(t), is_p_b(s);
{
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]);
is_p_a[i] = true;
is_p_b[r] = true;
}
}
}
const int m = (int)points.size();
std::vector<std::pair<int, int>> condition(m);
{
int r1 = 0, r2 = 0;
for (int i = 0; i < m; ++i) {
while (a[r1] < points[i]) {
++r1;
}
while (b[r2] < points[i]) {
++r2;
}
condition[i] = {r1, r2};
}
}
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;
for (int i = 1; i < t; ++i) {
// dp[s + i][s]
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;
}
Compilation message
cigle.cpp: In function 'int main()':
cigle.cpp:67:13: warning: unused variable 'max_v' [-Wunused-variable]
67 | int max_v = 0;
| ^~~~~
cigle.cpp:69:13: warning: unused variable 'r' [-Wunused-variable]
69 | int r = 0;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
304 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 |
304 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
304 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 |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
300 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
2 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
300 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
160 ms |
1324 KB |
Output is correct |
2 |
Correct |
174 ms |
1428 KB |
Output is correct |
3 |
Correct |
175 ms |
1356 KB |
Output is correct |
4 |
Correct |
168 ms |
1236 KB |
Output is correct |
5 |
Correct |
171 ms |
1324 KB |
Output is correct |
6 |
Correct |
170 ms |
1320 KB |
Output is correct |
7 |
Correct |
167 ms |
1320 KB |
Output is correct |
8 |
Correct |
168 ms |
1308 KB |
Output is correct |
9 |
Correct |
172 ms |
1440 KB |
Output is correct |
10 |
Correct |
163 ms |
1236 KB |
Output is correct |
11 |
Correct |
162 ms |
1320 KB |
Output is correct |
12 |
Correct |
154 ms |
1428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
304 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 |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
300 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
2 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
300 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
160 ms |
1324 KB |
Output is correct |
22 |
Correct |
174 ms |
1428 KB |
Output is correct |
23 |
Correct |
175 ms |
1356 KB |
Output is correct |
24 |
Correct |
168 ms |
1236 KB |
Output is correct |
25 |
Correct |
171 ms |
1324 KB |
Output is correct |
26 |
Correct |
170 ms |
1320 KB |
Output is correct |
27 |
Correct |
167 ms |
1320 KB |
Output is correct |
28 |
Correct |
168 ms |
1308 KB |
Output is correct |
29 |
Correct |
172 ms |
1440 KB |
Output is correct |
30 |
Correct |
163 ms |
1236 KB |
Output is correct |
31 |
Correct |
162 ms |
1320 KB |
Output is correct |
32 |
Correct |
154 ms |
1428 KB |
Output is correct |
33 |
Correct |
158 ms |
1348 KB |
Output is correct |
34 |
Correct |
164 ms |
1312 KB |
Output is correct |
35 |
Correct |
165 ms |
1236 KB |
Output is correct |
36 |
Correct |
176 ms |
1352 KB |
Output is correct |
37 |
Correct |
167 ms |
1312 KB |
Output is correct |
38 |
Correct |
169 ms |
1236 KB |
Output is correct |
39 |
Correct |
123 ms |
1304 KB |
Output is correct |
40 |
Correct |
32 ms |
1336 KB |
Output is correct |
41 |
Correct |
43 ms |
1320 KB |
Output is correct |
42 |
Correct |
59 ms |
1304 KB |
Output is correct |
43 |
Correct |
51 ms |
1316 KB |
Output is correct |
44 |
Correct |
35 ms |
1236 KB |
Output is correct |
45 |
Correct |
49 ms |
1316 KB |
Output is correct |
46 |
Correct |
47 ms |
1324 KB |
Output is correct |
47 |
Correct |
44 ms |
1448 KB |
Output is correct |
48 |
Correct |
45 ms |
1312 KB |
Output is correct |
49 |
Correct |
52 ms |
1440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
304 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 |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
300 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
2 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
300 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
160 ms |
1324 KB |
Output is correct |
22 |
Correct |
174 ms |
1428 KB |
Output is correct |
23 |
Correct |
175 ms |
1356 KB |
Output is correct |
24 |
Correct |
168 ms |
1236 KB |
Output is correct |
25 |
Correct |
171 ms |
1324 KB |
Output is correct |
26 |
Correct |
170 ms |
1320 KB |
Output is correct |
27 |
Correct |
167 ms |
1320 KB |
Output is correct |
28 |
Correct |
168 ms |
1308 KB |
Output is correct |
29 |
Correct |
172 ms |
1440 KB |
Output is correct |
30 |
Correct |
163 ms |
1236 KB |
Output is correct |
31 |
Correct |
162 ms |
1320 KB |
Output is correct |
32 |
Correct |
154 ms |
1428 KB |
Output is correct |
33 |
Correct |
158 ms |
1348 KB |
Output is correct |
34 |
Correct |
164 ms |
1312 KB |
Output is correct |
35 |
Correct |
165 ms |
1236 KB |
Output is correct |
36 |
Correct |
176 ms |
1352 KB |
Output is correct |
37 |
Correct |
167 ms |
1312 KB |
Output is correct |
38 |
Correct |
169 ms |
1236 KB |
Output is correct |
39 |
Correct |
123 ms |
1304 KB |
Output is correct |
40 |
Correct |
32 ms |
1336 KB |
Output is correct |
41 |
Correct |
43 ms |
1320 KB |
Output is correct |
42 |
Correct |
59 ms |
1304 KB |
Output is correct |
43 |
Correct |
51 ms |
1316 KB |
Output is correct |
44 |
Correct |
35 ms |
1236 KB |
Output is correct |
45 |
Correct |
49 ms |
1316 KB |
Output is correct |
46 |
Correct |
47 ms |
1324 KB |
Output is correct |
47 |
Correct |
44 ms |
1448 KB |
Output is correct |
48 |
Correct |
45 ms |
1312 KB |
Output is correct |
49 |
Correct |
52 ms |
1440 KB |
Output is correct |
50 |
Execution timed out |
1089 ms |
98464 KB |
Time limit exceeded |
51 |
Halted |
0 ms |
0 KB |
- |