#include "towers.h"
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> a;
void init(int N, std::vector<int> H) {
n = N;
a = H;
}
int max_towers(int L, int R, int D) {
vector<vector<int>> srt;
for(int i = L; i <= R; ++i){
srt.push_back({a[i], i});
}
sort(srt.begin(), srt.end());
vector<vector<int>> ran;
for(int i = 0; i < (int)srt.size(); ++i){
int now = srt[i][1];
int r = now + 1, can = 1;
while(r <= R && a[r] < a[now] + D){
++r;
}
int l = now - 1;
while(l >= L && a[l] < a[now] + D){
--l;
}
ran.push_back({l + 1, r - 1});
}
sort(ran.begin(), ran.end(), [&](vector<int>&x, vector<int>&y){return x[1] < y[1];});
int ans = 0, mx = -1;
for(int i = 0; i < (int)ran.size(); ++i){
if(ran[i][0] > mx){
++ans;
mx = ran[i][1];
}
}
return ans;
}
Compilation message
towers.cpp: In function 'int max_towers(int, int, int)':
towers.cpp:26:26: warning: unused variable 'can' [-Wunused-variable]
26 | int r = now + 1, can = 1;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4054 ms |
6484 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
336 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 |
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 |
1 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 |
464 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 |
464 KB |
Output is correct |
21 |
Correct |
1 ms |
464 KB |
Output is correct |
22 |
Correct |
1 ms |
464 KB |
Output is correct |
23 |
Correct |
3 ms |
464 KB |
Output is correct |
24 |
Correct |
1 ms |
464 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
3 ms |
464 KB |
Output is correct |
27 |
Correct |
2 ms |
464 KB |
Output is correct |
28 |
Correct |
2 ms |
464 KB |
Output is correct |
29 |
Correct |
2 ms |
464 KB |
Output is correct |
30 |
Correct |
2 ms |
464 KB |
Output is correct |
31 |
Correct |
2 ms |
424 KB |
Output is correct |
32 |
Correct |
2 ms |
464 KB |
Output is correct |
33 |
Correct |
2 ms |
464 KB |
Output is correct |
34 |
Correct |
3 ms |
464 KB |
Output is correct |
35 |
Correct |
2 ms |
464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
336 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 |
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 |
1 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 |
464 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 |
464 KB |
Output is correct |
21 |
Correct |
1 ms |
464 KB |
Output is correct |
22 |
Correct |
1 ms |
464 KB |
Output is correct |
23 |
Correct |
3 ms |
464 KB |
Output is correct |
24 |
Correct |
1 ms |
464 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
3 ms |
464 KB |
Output is correct |
27 |
Correct |
2 ms |
464 KB |
Output is correct |
28 |
Correct |
2 ms |
464 KB |
Output is correct |
29 |
Correct |
2 ms |
464 KB |
Output is correct |
30 |
Correct |
2 ms |
464 KB |
Output is correct |
31 |
Correct |
2 ms |
424 KB |
Output is correct |
32 |
Correct |
2 ms |
464 KB |
Output is correct |
33 |
Correct |
2 ms |
464 KB |
Output is correct |
34 |
Correct |
3 ms |
464 KB |
Output is correct |
35 |
Correct |
2 ms |
464 KB |
Output is correct |
36 |
Correct |
22 ms |
3148 KB |
Output is correct |
37 |
Correct |
362 ms |
5572 KB |
Output is correct |
38 |
Correct |
42 ms |
2592 KB |
Output is correct |
39 |
Correct |
354 ms |
4548 KB |
Output is correct |
40 |
Correct |
33 ms |
2524 KB |
Output is correct |
41 |
Correct |
1272 ms |
11172 KB |
Output is correct |
42 |
Correct |
12 ms |
1352 KB |
Output is correct |
43 |
Correct |
731 ms |
6872 KB |
Output is correct |
44 |
Correct |
75 ms |
2596 KB |
Output is correct |
45 |
Correct |
13 ms |
1360 KB |
Output is correct |
46 |
Correct |
12 ms |
1360 KB |
Output is correct |
47 |
Correct |
26 ms |
5656 KB |
Output is correct |
48 |
Correct |
19 ms |
3592 KB |
Output is correct |
49 |
Correct |
22 ms |
1856 KB |
Output is correct |
50 |
Correct |
101 ms |
3668 KB |
Output is correct |
51 |
Correct |
293 ms |
5916 KB |
Output is correct |
52 |
Correct |
61 ms |
12432 KB |
Output is correct |
53 |
Correct |
61 ms |
12424 KB |
Output is correct |
54 |
Correct |
66 ms |
12448 KB |
Output is correct |
55 |
Correct |
1753 ms |
12596 KB |
Output is correct |
56 |
Correct |
1617 ms |
12424 KB |
Output is correct |
57 |
Correct |
2183 ms |
12188 KB |
Output is correct |
58 |
Correct |
1564 ms |
12432 KB |
Output is correct |
59 |
Correct |
901 ms |
12436 KB |
Output is correct |
60 |
Correct |
101 ms |
12500 KB |
Output is correct |
61 |
Correct |
858 ms |
12608 KB |
Output is correct |
62 |
Correct |
1471 ms |
12408 KB |
Output is correct |
63 |
Correct |
812 ms |
12492 KB |
Output is correct |
64 |
Correct |
3006 ms |
12408 KB |
Output is correct |
65 |
Correct |
3090 ms |
12540 KB |
Output is correct |
66 |
Correct |
2097 ms |
12468 KB |
Output is correct |
67 |
Correct |
3029 ms |
12504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4027 ms |
13032 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4037 ms |
3792 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
336 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 |
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 |
1 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 |
464 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 |
464 KB |
Output is correct |
21 |
Correct |
1 ms |
464 KB |
Output is correct |
22 |
Correct |
1 ms |
464 KB |
Output is correct |
23 |
Correct |
3 ms |
464 KB |
Output is correct |
24 |
Correct |
1 ms |
464 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
3 ms |
464 KB |
Output is correct |
27 |
Correct |
2 ms |
464 KB |
Output is correct |
28 |
Correct |
2 ms |
464 KB |
Output is correct |
29 |
Correct |
2 ms |
464 KB |
Output is correct |
30 |
Correct |
2 ms |
464 KB |
Output is correct |
31 |
Correct |
2 ms |
424 KB |
Output is correct |
32 |
Correct |
2 ms |
464 KB |
Output is correct |
33 |
Correct |
2 ms |
464 KB |
Output is correct |
34 |
Correct |
3 ms |
464 KB |
Output is correct |
35 |
Correct |
2 ms |
464 KB |
Output is correct |
36 |
Correct |
22 ms |
3148 KB |
Output is correct |
37 |
Correct |
362 ms |
5572 KB |
Output is correct |
38 |
Correct |
42 ms |
2592 KB |
Output is correct |
39 |
Correct |
354 ms |
4548 KB |
Output is correct |
40 |
Correct |
33 ms |
2524 KB |
Output is correct |
41 |
Correct |
1272 ms |
11172 KB |
Output is correct |
42 |
Correct |
12 ms |
1352 KB |
Output is correct |
43 |
Correct |
731 ms |
6872 KB |
Output is correct |
44 |
Correct |
75 ms |
2596 KB |
Output is correct |
45 |
Correct |
13 ms |
1360 KB |
Output is correct |
46 |
Correct |
12 ms |
1360 KB |
Output is correct |
47 |
Correct |
26 ms |
5656 KB |
Output is correct |
48 |
Correct |
19 ms |
3592 KB |
Output is correct |
49 |
Correct |
22 ms |
1856 KB |
Output is correct |
50 |
Correct |
101 ms |
3668 KB |
Output is correct |
51 |
Correct |
293 ms |
5916 KB |
Output is correct |
52 |
Correct |
61 ms |
12432 KB |
Output is correct |
53 |
Correct |
61 ms |
12424 KB |
Output is correct |
54 |
Correct |
66 ms |
12448 KB |
Output is correct |
55 |
Correct |
1753 ms |
12596 KB |
Output is correct |
56 |
Correct |
1617 ms |
12424 KB |
Output is correct |
57 |
Correct |
2183 ms |
12188 KB |
Output is correct |
58 |
Correct |
1564 ms |
12432 KB |
Output is correct |
59 |
Correct |
901 ms |
12436 KB |
Output is correct |
60 |
Correct |
101 ms |
12500 KB |
Output is correct |
61 |
Correct |
858 ms |
12608 KB |
Output is correct |
62 |
Correct |
1471 ms |
12408 KB |
Output is correct |
63 |
Correct |
812 ms |
12492 KB |
Output is correct |
64 |
Correct |
3006 ms |
12408 KB |
Output is correct |
65 |
Correct |
3090 ms |
12540 KB |
Output is correct |
66 |
Correct |
2097 ms |
12468 KB |
Output is correct |
67 |
Correct |
3029 ms |
12504 KB |
Output is correct |
68 |
Execution timed out |
4027 ms |
13032 KB |
Time limit exceeded |
69 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4054 ms |
6484 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |