#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct Tower {
int pos;
int h;
}towers[100000];
int height[100000];
int tower_cnt;
bool picked[100000];
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;
}
}
bool cmp(struct Tower t1, struct Tower t2) {
return t1.h < t2.h;
}
int max_towers(int L, int R, int D) {
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4043 ms |
1616 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
596 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 |
596 KB |
Output is correct |
13 |
Correct |
1 ms |
484 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 |
484 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 |
1 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 |
3 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
596 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 |
596 KB |
Output is correct |
13 |
Correct |
1 ms |
484 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 |
484 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 |
1 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 |
3 ms |
344 KB |
Output is correct |
36 |
Correct |
306 ms |
1732 KB |
Output is correct |
37 |
Correct |
208 ms |
2384 KB |
Output is correct |
38 |
Correct |
114 ms |
2632 KB |
Output is correct |
39 |
Correct |
54 ms |
2384 KB |
Output is correct |
40 |
Correct |
120 ms |
2380 KB |
Output is correct |
41 |
Correct |
3909 ms |
2380 KB |
Output is correct |
42 |
Correct |
19 ms |
2376 KB |
Output is correct |
43 |
Correct |
2393 ms |
2376 KB |
Output is correct |
44 |
Correct |
183 ms |
2360 KB |
Output is correct |
45 |
Correct |
19 ms |
2388 KB |
Output is correct |
46 |
Correct |
19 ms |
2380 KB |
Output is correct |
47 |
Correct |
1403 ms |
2380 KB |
Output is correct |
48 |
Correct |
357 ms |
2380 KB |
Output is correct |
49 |
Correct |
55 ms |
2376 KB |
Output is correct |
50 |
Correct |
452 ms |
2380 KB |
Output is correct |
51 |
Correct |
1078 ms |
2384 KB |
Output is correct |
52 |
Execution timed out |
4089 ms |
2380 KB |
Time limit exceeded |
53 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4016 ms |
2376 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4037 ms |
916 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
596 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 |
596 KB |
Output is correct |
13 |
Correct |
1 ms |
484 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 |
484 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 |
1 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 |
3 ms |
344 KB |
Output is correct |
36 |
Correct |
306 ms |
1732 KB |
Output is correct |
37 |
Correct |
208 ms |
2384 KB |
Output is correct |
38 |
Correct |
114 ms |
2632 KB |
Output is correct |
39 |
Correct |
54 ms |
2384 KB |
Output is correct |
40 |
Correct |
120 ms |
2380 KB |
Output is correct |
41 |
Correct |
3909 ms |
2380 KB |
Output is correct |
42 |
Correct |
19 ms |
2376 KB |
Output is correct |
43 |
Correct |
2393 ms |
2376 KB |
Output is correct |
44 |
Correct |
183 ms |
2360 KB |
Output is correct |
45 |
Correct |
19 ms |
2388 KB |
Output is correct |
46 |
Correct |
19 ms |
2380 KB |
Output is correct |
47 |
Correct |
1403 ms |
2380 KB |
Output is correct |
48 |
Correct |
357 ms |
2380 KB |
Output is correct |
49 |
Correct |
55 ms |
2376 KB |
Output is correct |
50 |
Correct |
452 ms |
2380 KB |
Output is correct |
51 |
Correct |
1078 ms |
2384 KB |
Output is correct |
52 |
Execution timed out |
4089 ms |
2380 KB |
Time limit exceeded |
53 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4043 ms |
1616 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |