#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct Tower {
int pos;
int h;
}towers[100000];
int height[100000];
int tower_cnt;
bool ok;
bool picked[100000];
int k;
void special_case(){
while (k < tower_cnt-1 and height[k] < height[k+1]){
k += 1;
}
for (int i = k;i < tower_cnt-1;i++){
if (height[i] <= height[i+1]){
ok = false;
}
}
}
void init(int N, vector<int> H) {
tower_cnt = N;
for (int i = 0; i < N; i++) {
height[i] = H[i];
towers[i].h = H[i];
towers[i].pos = i;
}
special_case();
}
bool cmp(struct Tower t1, struct Tower t2) {
return t1.h < t2.h;
}
int max_towers(int L, int R, int D) {
if (ok){
if ((L <= k and R <= k) or (L >= k and R >= k)){
return 1;
}
else if (height[L] <= height[k]-D and height[R] <= height[k]-D){
return 2;
}else{
return 1;
}
}else {
int ans = 0;
sort(towers, towers + tower_cnt, cmp);
/*for (int i = 0; i < tower_cnt; i++) {
cout << towers[i].pos << "\n";
}*/
for (int i = 0; i < tower_cnt; i++) {
int pos = towers[i].pos;
if (pos < L || pos > R) {
continue;
}
int h = towers[i].h;
bool valid = true;
int max_left = h;
for (int j = pos - 1; j >= L; j--) {
if (picked[j]) {
if (max_left - D < height[j] || max_left - D < h) {
valid = false;
break;
}
}
if (height[j] > max_left) {
max_left = height[j];
}
}
int max_right = h;
for (int j = pos + 1; j <= R; j++) {
if (picked[j]) {
if (max_right - D < height[j] || max_right - D < h) {
valid = false;
break;
}
}
if (height[j] > max_right) {
max_right = height[j];
}
}
if (valid) {
picked[pos] = true;
// cout << pos << "\n";
ans += 1;
}
}
return ans;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4054 ms |
1460 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
2 ms |
532 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
2 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
3 ms |
344 KB |
Output is correct |
21 |
Correct |
3 ms |
344 KB |
Output is correct |
22 |
Correct |
3 ms |
344 KB |
Output is correct |
23 |
Correct |
4 ms |
344 KB |
Output is correct |
24 |
Correct |
3 ms |
344 KB |
Output is correct |
25 |
Correct |
0 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
2 ms |
344 KB |
Output is correct |
28 |
Correct |
2 ms |
344 KB |
Output is correct |
29 |
Correct |
2 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
344 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Correct |
4 ms |
344 KB |
Output is correct |
33 |
Correct |
4 ms |
344 KB |
Output is correct |
34 |
Correct |
4 ms |
344 KB |
Output is correct |
35 |
Correct |
4 ms |
484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
2 ms |
532 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
2 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
3 ms |
344 KB |
Output is correct |
21 |
Correct |
3 ms |
344 KB |
Output is correct |
22 |
Correct |
3 ms |
344 KB |
Output is correct |
23 |
Correct |
4 ms |
344 KB |
Output is correct |
24 |
Correct |
3 ms |
344 KB |
Output is correct |
25 |
Correct |
0 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
2 ms |
344 KB |
Output is correct |
28 |
Correct |
2 ms |
344 KB |
Output is correct |
29 |
Correct |
2 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
344 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Correct |
4 ms |
344 KB |
Output is correct |
33 |
Correct |
4 ms |
344 KB |
Output is correct |
34 |
Correct |
4 ms |
344 KB |
Output is correct |
35 |
Correct |
4 ms |
484 KB |
Output is correct |
36 |
Correct |
333 ms |
1732 KB |
Output is correct |
37 |
Correct |
226 ms |
2384 KB |
Output is correct |
38 |
Correct |
112 ms |
2372 KB |
Output is correct |
39 |
Correct |
58 ms |
2376 KB |
Output is correct |
40 |
Correct |
133 ms |
2376 KB |
Output is correct |
41 |
Execution timed out |
4053 ms |
2376 KB |
Time limit exceeded |
42 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4050 ms |
2376 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4061 ms |
920 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
2 ms |
532 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
2 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
3 ms |
344 KB |
Output is correct |
21 |
Correct |
3 ms |
344 KB |
Output is correct |
22 |
Correct |
3 ms |
344 KB |
Output is correct |
23 |
Correct |
4 ms |
344 KB |
Output is correct |
24 |
Correct |
3 ms |
344 KB |
Output is correct |
25 |
Correct |
0 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
2 ms |
344 KB |
Output is correct |
28 |
Correct |
2 ms |
344 KB |
Output is correct |
29 |
Correct |
2 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
344 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Correct |
4 ms |
344 KB |
Output is correct |
33 |
Correct |
4 ms |
344 KB |
Output is correct |
34 |
Correct |
4 ms |
344 KB |
Output is correct |
35 |
Correct |
4 ms |
484 KB |
Output is correct |
36 |
Correct |
333 ms |
1732 KB |
Output is correct |
37 |
Correct |
226 ms |
2384 KB |
Output is correct |
38 |
Correct |
112 ms |
2372 KB |
Output is correct |
39 |
Correct |
58 ms |
2376 KB |
Output is correct |
40 |
Correct |
133 ms |
2376 KB |
Output is correct |
41 |
Execution timed out |
4053 ms |
2376 KB |
Time limit exceeded |
42 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4054 ms |
1460 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |