#include "towers.h"
#include <bits/stdc++.h>
using namespace std;
int glob_n;
vector<int> glob_h;
void init(int nn, vector<int> hh) {
glob_n = nn;
glob_h = hh;
}
int max_towers(int l, int r, int d) {
assert(0 <= l && l <= r && r < glob_n);
vector<int> inds;
for (int i = l; i <= r; i++) {
inds.push_back(i);
}
sort(inds.begin(), inds.end(), [&] (int i, int j) {
return glob_h[i] < glob_h[j];});
vector<bool> used(r - l + 1, 0);
int solution = 0;
for (auto &i : inds) {
bool ok = 1;
int mx = 0;
for (int j = i + 1; j <= r && ok; j++) {
if (used[j - l] && mx < glob_h[i] + d) {
ok = 0;
}
mx = max(mx, glob_h[j]);
}
mx = 0;
for (int j = i - 1; j >= l && ok; j--) {
if (used[j - l] && mx < glob_h[i] + d) {
ok = 0;
}
mx = max(mx, glob_h[j]);
}
solution += ok;
used[i - l] = ok;
}
return solution;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4049 ms |
1356 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 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 |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
208 KB |
Output is correct |
11 |
Correct |
1 ms |
208 KB |
Output is correct |
12 |
Correct |
0 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
208 KB |
Output is correct |
14 |
Correct |
1 ms |
208 KB |
Output is correct |
15 |
Correct |
1 ms |
208 KB |
Output is correct |
16 |
Correct |
3 ms |
208 KB |
Output is correct |
17 |
Correct |
1 ms |
208 KB |
Output is correct |
18 |
Correct |
1 ms |
208 KB |
Output is correct |
19 |
Correct |
1 ms |
208 KB |
Output is correct |
20 |
Correct |
4 ms |
216 KB |
Output is correct |
21 |
Correct |
5 ms |
208 KB |
Output is correct |
22 |
Correct |
5 ms |
208 KB |
Output is correct |
23 |
Correct |
3 ms |
208 KB |
Output is correct |
24 |
Correct |
3 ms |
208 KB |
Output is correct |
25 |
Correct |
1 ms |
208 KB |
Output is correct |
26 |
Correct |
2 ms |
208 KB |
Output is correct |
27 |
Correct |
3 ms |
208 KB |
Output is correct |
28 |
Correct |
3 ms |
208 KB |
Output is correct |
29 |
Correct |
4 ms |
208 KB |
Output is correct |
30 |
Correct |
2 ms |
208 KB |
Output is correct |
31 |
Correct |
2 ms |
208 KB |
Output is correct |
32 |
Correct |
5 ms |
208 KB |
Output is correct |
33 |
Correct |
3 ms |
208 KB |
Output is correct |
34 |
Correct |
5 ms |
328 KB |
Output is correct |
35 |
Correct |
1 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 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 |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
208 KB |
Output is correct |
11 |
Correct |
1 ms |
208 KB |
Output is correct |
12 |
Correct |
0 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
208 KB |
Output is correct |
14 |
Correct |
1 ms |
208 KB |
Output is correct |
15 |
Correct |
1 ms |
208 KB |
Output is correct |
16 |
Correct |
3 ms |
208 KB |
Output is correct |
17 |
Correct |
1 ms |
208 KB |
Output is correct |
18 |
Correct |
1 ms |
208 KB |
Output is correct |
19 |
Correct |
1 ms |
208 KB |
Output is correct |
20 |
Correct |
4 ms |
216 KB |
Output is correct |
21 |
Correct |
5 ms |
208 KB |
Output is correct |
22 |
Correct |
5 ms |
208 KB |
Output is correct |
23 |
Correct |
3 ms |
208 KB |
Output is correct |
24 |
Correct |
3 ms |
208 KB |
Output is correct |
25 |
Correct |
1 ms |
208 KB |
Output is correct |
26 |
Correct |
2 ms |
208 KB |
Output is correct |
27 |
Correct |
3 ms |
208 KB |
Output is correct |
28 |
Correct |
3 ms |
208 KB |
Output is correct |
29 |
Correct |
4 ms |
208 KB |
Output is correct |
30 |
Correct |
2 ms |
208 KB |
Output is correct |
31 |
Correct |
2 ms |
208 KB |
Output is correct |
32 |
Correct |
5 ms |
208 KB |
Output is correct |
33 |
Correct |
3 ms |
208 KB |
Output is correct |
34 |
Correct |
5 ms |
328 KB |
Output is correct |
35 |
Correct |
1 ms |
208 KB |
Output is correct |
36 |
Correct |
365 ms |
1076 KB |
Output is correct |
37 |
Correct |
246 ms |
1480 KB |
Output is correct |
38 |
Correct |
141 ms |
1436 KB |
Output is correct |
39 |
Correct |
60 ms |
1352 KB |
Output is correct |
40 |
Correct |
184 ms |
1448 KB |
Output is correct |
41 |
Execution timed out |
4046 ms |
1856 KB |
Time limit exceeded |
42 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4059 ms |
1480 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4074 ms |
844 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 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 |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
208 KB |
Output is correct |
11 |
Correct |
1 ms |
208 KB |
Output is correct |
12 |
Correct |
0 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
208 KB |
Output is correct |
14 |
Correct |
1 ms |
208 KB |
Output is correct |
15 |
Correct |
1 ms |
208 KB |
Output is correct |
16 |
Correct |
3 ms |
208 KB |
Output is correct |
17 |
Correct |
1 ms |
208 KB |
Output is correct |
18 |
Correct |
1 ms |
208 KB |
Output is correct |
19 |
Correct |
1 ms |
208 KB |
Output is correct |
20 |
Correct |
4 ms |
216 KB |
Output is correct |
21 |
Correct |
5 ms |
208 KB |
Output is correct |
22 |
Correct |
5 ms |
208 KB |
Output is correct |
23 |
Correct |
3 ms |
208 KB |
Output is correct |
24 |
Correct |
3 ms |
208 KB |
Output is correct |
25 |
Correct |
1 ms |
208 KB |
Output is correct |
26 |
Correct |
2 ms |
208 KB |
Output is correct |
27 |
Correct |
3 ms |
208 KB |
Output is correct |
28 |
Correct |
3 ms |
208 KB |
Output is correct |
29 |
Correct |
4 ms |
208 KB |
Output is correct |
30 |
Correct |
2 ms |
208 KB |
Output is correct |
31 |
Correct |
2 ms |
208 KB |
Output is correct |
32 |
Correct |
5 ms |
208 KB |
Output is correct |
33 |
Correct |
3 ms |
208 KB |
Output is correct |
34 |
Correct |
5 ms |
328 KB |
Output is correct |
35 |
Correct |
1 ms |
208 KB |
Output is correct |
36 |
Correct |
365 ms |
1076 KB |
Output is correct |
37 |
Correct |
246 ms |
1480 KB |
Output is correct |
38 |
Correct |
141 ms |
1436 KB |
Output is correct |
39 |
Correct |
60 ms |
1352 KB |
Output is correct |
40 |
Correct |
184 ms |
1448 KB |
Output is correct |
41 |
Execution timed out |
4046 ms |
1856 KB |
Time limit exceeded |
42 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4049 ms |
1356 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |