#include "towers.h"
#include <vector>
#include <iostream>
std::vector<int> real_h(0);
int maxi = 0;
void init(int N, std::vector<int> H) {
real_h.resize(N);
for (int i = 0; i < N; i++) {
real_h[i] = H[i];
if (real_h[i] > maxi) {
maxi = real_h[i];
}
}
}
int get_max_id(int l, int r) {
int max_result = real_h[l];
int max_id =l;
for (int i = l + 1; i <= r; i++) {
if (real_h[i] > max_result) {
max_result = real_h[i];
max_id = i;
}
}
return max_id;
}
int get_min_id(int l, int r) {
int min_result= real_h[l];
int min_id =l;
for (int i = l + 1; i <= r; i++) {
if (real_h[i] < min_result) {
min_result = real_h[i];
min_id = i;
}
}
return min_id;
}
int max_towers2(int l, int r, int d, int max_possible_value) {
if (l > r) {
return 0;
}
if (l == r) {
if (real_h[l] <= max_possible_value) {
return 1;
}
return 0;
}
if (l + 1 == r) {
if (real_h[l] <= max_possible_value || real_h[l + 1] <= max_possible_value) {
return 1;
}
return 0;
}
int max_id = get_max_id(l, r);
int left_value = max_towers2(l, max_id - 1, d, real_h[max_id] - d);
int right_value = max_towers2(max_id + 1, r, d, real_h[max_id] - d);
if (left_value + right_value == 0) {
int min_id = get_min_id(l, r);
if (real_h[min_id] <= max_possible_value) {
return 1;
}
}
return left_value + right_value;
}
int max_towers(int L, int R, int D) {
return max_towers2(L, R, D, maxi);
}
/*int main() {
init(7, std::vector<int>{10, 20, 60, 40, 50, 30, 70});
std::cout << max_towers(1, 5, 10) << std::endl;
std::cout << max_towers(2, 2, 100) << std::endl;
std::cout << max_towers(0, 6, 17) << std::endl;
}*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4070 ms |
4444 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
208 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
0 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
208 KB |
Output is correct |
16 |
Correct |
1 ms |
208 KB |
Output is correct |
17 |
Correct |
1 ms |
208 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
208 KB |
Output is correct |
21 |
Correct |
1 ms |
248 KB |
Output is correct |
22 |
Correct |
1 ms |
208 KB |
Output is correct |
23 |
Correct |
2 ms |
464 KB |
Output is correct |
24 |
Correct |
2 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
256 KB |
Output is correct |
26 |
Correct |
1 ms |
208 KB |
Output is correct |
27 |
Correct |
1 ms |
208 KB |
Output is correct |
28 |
Correct |
1 ms |
256 KB |
Output is correct |
29 |
Correct |
1 ms |
208 KB |
Output is correct |
30 |
Correct |
1 ms |
208 KB |
Output is correct |
31 |
Correct |
1 ms |
208 KB |
Output is correct |
32 |
Correct |
2 ms |
464 KB |
Output is correct |
33 |
Correct |
5 ms |
464 KB |
Output is correct |
34 |
Correct |
5 ms |
384 KB |
Output is correct |
35 |
Correct |
2 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
208 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
0 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
208 KB |
Output is correct |
16 |
Correct |
1 ms |
208 KB |
Output is correct |
17 |
Correct |
1 ms |
208 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
208 KB |
Output is correct |
21 |
Correct |
1 ms |
248 KB |
Output is correct |
22 |
Correct |
1 ms |
208 KB |
Output is correct |
23 |
Correct |
2 ms |
464 KB |
Output is correct |
24 |
Correct |
2 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
256 KB |
Output is correct |
26 |
Correct |
1 ms |
208 KB |
Output is correct |
27 |
Correct |
1 ms |
208 KB |
Output is correct |
28 |
Correct |
1 ms |
256 KB |
Output is correct |
29 |
Correct |
1 ms |
208 KB |
Output is correct |
30 |
Correct |
1 ms |
208 KB |
Output is correct |
31 |
Correct |
1 ms |
208 KB |
Output is correct |
32 |
Correct |
2 ms |
464 KB |
Output is correct |
33 |
Correct |
5 ms |
464 KB |
Output is correct |
34 |
Correct |
5 ms |
384 KB |
Output is correct |
35 |
Correct |
2 ms |
504 KB |
Output is correct |
36 |
Correct |
9 ms |
1052 KB |
Output is correct |
37 |
Correct |
22 ms |
1436 KB |
Output is correct |
38 |
Correct |
21 ms |
1492 KB |
Output is correct |
39 |
Correct |
19 ms |
1456 KB |
Output is correct |
40 |
Correct |
13 ms |
1360 KB |
Output is correct |
41 |
Correct |
24 ms |
1460 KB |
Output is correct |
42 |
Correct |
13 ms |
1440 KB |
Output is correct |
43 |
Correct |
1468 ms |
5064 KB |
Output is correct |
44 |
Correct |
124 ms |
2044 KB |
Output is correct |
45 |
Correct |
28 ms |
1484 KB |
Output is correct |
46 |
Correct |
21 ms |
1440 KB |
Output is correct |
47 |
Correct |
22 ms |
1360 KB |
Output is correct |
48 |
Correct |
22 ms |
1444 KB |
Output is correct |
49 |
Correct |
21 ms |
1416 KB |
Output is correct |
50 |
Correct |
232 ms |
2720 KB |
Output is correct |
51 |
Correct |
783 ms |
3992 KB |
Output is correct |
52 |
Correct |
16 ms |
1468 KB |
Output is correct |
53 |
Correct |
21 ms |
1464 KB |
Output is correct |
54 |
Correct |
26 ms |
1420 KB |
Output is correct |
55 |
Execution timed out |
4013 ms |
7924 KB |
Time limit exceeded |
56 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4085 ms |
1440 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4074 ms |
508 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
208 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
0 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
208 KB |
Output is correct |
16 |
Correct |
1 ms |
208 KB |
Output is correct |
17 |
Correct |
1 ms |
208 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
208 KB |
Output is correct |
21 |
Correct |
1 ms |
248 KB |
Output is correct |
22 |
Correct |
1 ms |
208 KB |
Output is correct |
23 |
Correct |
2 ms |
464 KB |
Output is correct |
24 |
Correct |
2 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
256 KB |
Output is correct |
26 |
Correct |
1 ms |
208 KB |
Output is correct |
27 |
Correct |
1 ms |
208 KB |
Output is correct |
28 |
Correct |
1 ms |
256 KB |
Output is correct |
29 |
Correct |
1 ms |
208 KB |
Output is correct |
30 |
Correct |
1 ms |
208 KB |
Output is correct |
31 |
Correct |
1 ms |
208 KB |
Output is correct |
32 |
Correct |
2 ms |
464 KB |
Output is correct |
33 |
Correct |
5 ms |
464 KB |
Output is correct |
34 |
Correct |
5 ms |
384 KB |
Output is correct |
35 |
Correct |
2 ms |
504 KB |
Output is correct |
36 |
Correct |
9 ms |
1052 KB |
Output is correct |
37 |
Correct |
22 ms |
1436 KB |
Output is correct |
38 |
Correct |
21 ms |
1492 KB |
Output is correct |
39 |
Correct |
19 ms |
1456 KB |
Output is correct |
40 |
Correct |
13 ms |
1360 KB |
Output is correct |
41 |
Correct |
24 ms |
1460 KB |
Output is correct |
42 |
Correct |
13 ms |
1440 KB |
Output is correct |
43 |
Correct |
1468 ms |
5064 KB |
Output is correct |
44 |
Correct |
124 ms |
2044 KB |
Output is correct |
45 |
Correct |
28 ms |
1484 KB |
Output is correct |
46 |
Correct |
21 ms |
1440 KB |
Output is correct |
47 |
Correct |
22 ms |
1360 KB |
Output is correct |
48 |
Correct |
22 ms |
1444 KB |
Output is correct |
49 |
Correct |
21 ms |
1416 KB |
Output is correct |
50 |
Correct |
232 ms |
2720 KB |
Output is correct |
51 |
Correct |
783 ms |
3992 KB |
Output is correct |
52 |
Correct |
16 ms |
1468 KB |
Output is correct |
53 |
Correct |
21 ms |
1464 KB |
Output is correct |
54 |
Correct |
26 ms |
1420 KB |
Output is correct |
55 |
Execution timed out |
4013 ms |
7924 KB |
Time limit exceeded |
56 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4070 ms |
4444 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |