#include "towers.h"
#include <bits/stdc++.h>
using namespace std;
#define OPTM ios_base::sync_with_stdio(0); cin.tie(0);
#define INF int(1e9+7)
#define ln '\n'
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define FOR(i,s,n) for (int i = s; i < n; i++)
#define FORR(i,n,s) for (int i = n; i > s; i--)
#define FORX(u, arr) for (auto u : arr)
#define PB push_back
#define in(v,x) (v.find(x) != v.end())
#define F first
#define S second
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define UM unordered_map
#define US unordered_set
#define PQ priority_queue
#define ALL(v) v.begin(), v.end()
const ll LLINF = 1e18+1;
const int MAXN = 1e5+5;
int n,l,r,d;
int h[MAXN];
US<int> s;
bool check(int start) {
FORR(i,start-1,-1) {
if (s.count(i)) return 0;
if (h[i] >= h[start]+d) return 1;
}
return 1;
}
bool check1(int start) {
FOR(i,start+1,n) {
if (s.count(i)) return 0;
if (h[i] >= h[start]+d) return 1;
}
return 1;
}
void init(int N, std::vector<int> H) {
n = N;
FOR(i,0,n) h[i] = H[i];
}
int max_towers(int L, int R, int D) {
s.clear();
l = L, r = R, d = D;
vector<PII> v;
FOR(i,l,r+1) v.PB({h[i],i});
sort(ALL(v));
int vn = v.size();
FOR(i,0,vn) {
int curh = v[i].F, idx = v[i].S;
if (check(idx) && check1(idx)) s.insert(idx);
}
return s.size();
}
Compilation message
towers.cpp: In function 'int max_towers(int, int, int)':
towers.cpp:60:13: warning: unused variable 'curh' [-Wunused-variable]
60 | int curh = v[i].F, idx = v[i].S;
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4090 ms |
1184 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
220 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
208 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 |
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 |
2 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 |
3 ms |
208 KB |
Output is correct |
14 |
Correct |
2 ms |
208 KB |
Output is correct |
15 |
Correct |
1 ms |
208 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
0 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
208 KB |
Output is correct |
19 |
Correct |
1 ms |
208 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 |
11 ms |
336 KB |
Output is correct |
24 |
Correct |
4 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
208 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 |
11 ms |
336 KB |
Output is correct |
33 |
Correct |
19 ms |
336 KB |
Output is correct |
34 |
Correct |
11 ms |
352 KB |
Output is correct |
35 |
Correct |
5 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
220 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
208 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 |
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 |
2 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 |
3 ms |
208 KB |
Output is correct |
14 |
Correct |
2 ms |
208 KB |
Output is correct |
15 |
Correct |
1 ms |
208 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
0 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
208 KB |
Output is correct |
19 |
Correct |
1 ms |
208 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 |
11 ms |
336 KB |
Output is correct |
24 |
Correct |
4 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
208 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 |
11 ms |
336 KB |
Output is correct |
33 |
Correct |
19 ms |
336 KB |
Output is correct |
34 |
Correct |
11 ms |
352 KB |
Output is correct |
35 |
Correct |
5 ms |
336 KB |
Output is correct |
36 |
Correct |
8 ms |
1196 KB |
Output is correct |
37 |
Correct |
20 ms |
1832 KB |
Output is correct |
38 |
Correct |
11 ms |
1472 KB |
Output is correct |
39 |
Correct |
30 ms |
1528 KB |
Output is correct |
40 |
Correct |
10 ms |
1444 KB |
Output is correct |
41 |
Correct |
29 ms |
2632 KB |
Output is correct |
42 |
Correct |
15 ms |
1444 KB |
Output is correct |
43 |
Execution timed out |
4062 ms |
1956 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4097 ms |
3700 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4089 ms |
1132 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
220 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
208 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 |
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 |
2 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 |
3 ms |
208 KB |
Output is correct |
14 |
Correct |
2 ms |
208 KB |
Output is correct |
15 |
Correct |
1 ms |
208 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
0 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
208 KB |
Output is correct |
19 |
Correct |
1 ms |
208 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 |
11 ms |
336 KB |
Output is correct |
24 |
Correct |
4 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
208 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 |
11 ms |
336 KB |
Output is correct |
33 |
Correct |
19 ms |
336 KB |
Output is correct |
34 |
Correct |
11 ms |
352 KB |
Output is correct |
35 |
Correct |
5 ms |
336 KB |
Output is correct |
36 |
Correct |
8 ms |
1196 KB |
Output is correct |
37 |
Correct |
20 ms |
1832 KB |
Output is correct |
38 |
Correct |
11 ms |
1472 KB |
Output is correct |
39 |
Correct |
30 ms |
1528 KB |
Output is correct |
40 |
Correct |
10 ms |
1444 KB |
Output is correct |
41 |
Correct |
29 ms |
2632 KB |
Output is correct |
42 |
Correct |
15 ms |
1444 KB |
Output is correct |
43 |
Execution timed out |
4062 ms |
1956 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4090 ms |
1184 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |