#include "towers.h"
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> arr;
int sort_index[101010];
void init(int N, vector<int> H) {
n = N;
vector< pair<int, int> > temp;
for (int i = 0; i < N; i++) arr.push_back(H[i]);
for (int i = 0; i < N; i++) temp.push_back({H[i], i});
sort(temp.begin(), temp.end());
for (int i = 0; i < N; i++) {
sort_index[i] = temp[i].second;
}
}
int ch[101010];
int max_towers(int L, int R, int D) {
int ans = 0;
for (int i = 0; i < n; i++) ch[i] = 0;
for (int i = 0; i < n; i++) {
if (sort_index[i] < L || sort_index[i] > R) continue;
bool f = true;
int maxval = 0;
for (int j = sort_index[i] + 1; j <= R; j++) {
if (ch[j] == 1) {
if (maxval < max(arr[sort_index[i]], arr[j]) + D) f = false;
break;
}
maxval = max(maxval, arr[j]);
}
maxval = 0;
for (int j = sort_index[i] - 1; j >= L; j--) {
if (ch[j] == 1) {
if (maxval < max(arr[sort_index[i]], arr[j]) + D) f = false;
break;
}
maxval = max(maxval, arr[j]);
}
if (f) {
ans++;
ch[sort_index[i]] = 1;
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4024 ms |
1828 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
284 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
0 ms |
208 KB |
Output is correct |
13 |
Correct |
3 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
5 ms |
336 KB |
Output is correct |
24 |
Correct |
3 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
5 ms |
304 KB |
Output is correct |
33 |
Correct |
5 ms |
372 KB |
Output is correct |
34 |
Correct |
5 ms |
336 KB |
Output is correct |
35 |
Correct |
3 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
284 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
0 ms |
208 KB |
Output is correct |
13 |
Correct |
3 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
5 ms |
336 KB |
Output is correct |
24 |
Correct |
3 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
5 ms |
304 KB |
Output is correct |
33 |
Correct |
5 ms |
372 KB |
Output is correct |
34 |
Correct |
5 ms |
336 KB |
Output is correct |
35 |
Correct |
3 ms |
336 KB |
Output is correct |
36 |
Correct |
20 ms |
1952 KB |
Output is correct |
37 |
Correct |
32 ms |
2716 KB |
Output is correct |
38 |
Correct |
23 ms |
2752 KB |
Output is correct |
39 |
Correct |
27 ms |
2676 KB |
Output is correct |
40 |
Correct |
24 ms |
2700 KB |
Output is correct |
41 |
Correct |
28 ms |
2752 KB |
Output is correct |
42 |
Correct |
24 ms |
2716 KB |
Output is correct |
43 |
Correct |
2777 ms |
2752 KB |
Output is correct |
44 |
Correct |
219 ms |
2716 KB |
Output is correct |
45 |
Correct |
24 ms |
2752 KB |
Output is correct |
46 |
Correct |
20 ms |
2680 KB |
Output is correct |
47 |
Correct |
25 ms |
2740 KB |
Output is correct |
48 |
Correct |
23 ms |
2668 KB |
Output is correct |
49 |
Correct |
23 ms |
2752 KB |
Output is correct |
50 |
Correct |
528 ms |
2752 KB |
Output is correct |
51 |
Correct |
1296 ms |
2728 KB |
Output is correct |
52 |
Correct |
29 ms |
2840 KB |
Output is correct |
53 |
Correct |
34 ms |
2720 KB |
Output is correct |
54 |
Correct |
28 ms |
2712 KB |
Output is correct |
55 |
Execution timed out |
4035 ms |
2672 KB |
Time limit exceeded |
56 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4072 ms |
2760 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4042 ms |
976 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
284 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
0 ms |
208 KB |
Output is correct |
13 |
Correct |
3 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
5 ms |
336 KB |
Output is correct |
24 |
Correct |
3 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
5 ms |
304 KB |
Output is correct |
33 |
Correct |
5 ms |
372 KB |
Output is correct |
34 |
Correct |
5 ms |
336 KB |
Output is correct |
35 |
Correct |
3 ms |
336 KB |
Output is correct |
36 |
Correct |
20 ms |
1952 KB |
Output is correct |
37 |
Correct |
32 ms |
2716 KB |
Output is correct |
38 |
Correct |
23 ms |
2752 KB |
Output is correct |
39 |
Correct |
27 ms |
2676 KB |
Output is correct |
40 |
Correct |
24 ms |
2700 KB |
Output is correct |
41 |
Correct |
28 ms |
2752 KB |
Output is correct |
42 |
Correct |
24 ms |
2716 KB |
Output is correct |
43 |
Correct |
2777 ms |
2752 KB |
Output is correct |
44 |
Correct |
219 ms |
2716 KB |
Output is correct |
45 |
Correct |
24 ms |
2752 KB |
Output is correct |
46 |
Correct |
20 ms |
2680 KB |
Output is correct |
47 |
Correct |
25 ms |
2740 KB |
Output is correct |
48 |
Correct |
23 ms |
2668 KB |
Output is correct |
49 |
Correct |
23 ms |
2752 KB |
Output is correct |
50 |
Correct |
528 ms |
2752 KB |
Output is correct |
51 |
Correct |
1296 ms |
2728 KB |
Output is correct |
52 |
Correct |
29 ms |
2840 KB |
Output is correct |
53 |
Correct |
34 ms |
2720 KB |
Output is correct |
54 |
Correct |
28 ms |
2712 KB |
Output is correct |
55 |
Execution timed out |
4035 ms |
2672 KB |
Time limit exceeded |
56 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4024 ms |
1828 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |