#include <bits/stdc++.h>
#include "towers.h"
#define ll long long
#define ar array
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
using namespace std;
template<typename T> bool ckmin(T &a, const T &b ) { return a > b ? a = b, 1 : 0; }
template<typename T> bool ckmax(T &a, const T &b ) { return a < b ? a = b, 1 : 0; }
int N; vector<int> h;
void init(int _N, std::vector<int> H) {
N = _N;
h = H;
}
struct seg {
int N; vector<ar<int, 2>> tree;
seg(int n, const vector<int>& h) : N(1<<(__lg(n)+1)), tree(2*N) {
for (int i = 0; i < n; i++) tree[i+N] = {h[i], i};
for (int i = N-1; i >= 1; i--) tree[i] = max(tree[i*2], tree[i*2+1]);
}
ar<int, 2> query(int node, int nl, int nr, int ql, int qr) {
if (ql > nr || qr < nl) return {};
if (ql <= nl && nr <= qr) return tree[node];
int mid = (nl+nr)/2;
return max(query(node*2, nl, mid, ql, qr), query(node*2+1, mid+1, nr, ql, qr));
}
};
int max_towers(int L, int R, int D) {
seg st(N, h);
map<ar<int, 3>, int> mp;
auto solve = [&](auto&& s, int l, int r, int lim) -> int {
if (mp.count({l, r, lim})) return mp[{l, r, lim}];
if (l > r) return 0;
if (l == r) return h[l] <= lim;
int p = st.query(1, 0, st.N-1, l, r)[1];
return mp[{l, r, lim}] = max({s(s, l, p-1, lim), s(s, p+1, r, lim), int(h[p] <= lim), s(s, l, p-1, h[p] - D) + s(s, p+1, r, h[p] - D)});
};
solve(solve, L, R, 1e9);
return solve(solve, L, R, 1e9);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4062 ms |
168388 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
5 ms |
856 KB |
Output is correct |
3 |
Correct |
4 ms |
856 KB |
Output is correct |
4 |
Correct |
3 ms |
600 KB |
Output is correct |
5 |
Correct |
4 ms |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
3 ms |
600 KB |
Output is correct |
8 |
Correct |
15 ms |
2168 KB |
Output is correct |
9 |
Correct |
78 ms |
6916 KB |
Output is correct |
10 |
Correct |
9 ms |
1368 KB |
Output is correct |
11 |
Correct |
53 ms |
5240 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
399 ms |
23396 KB |
Output is correct |
14 |
Correct |
197 ms |
14416 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
4 ms |
856 KB |
Output is correct |
17 |
Correct |
2 ms |
492 KB |
Output is correct |
18 |
Correct |
44 ms |
4432 KB |
Output is correct |
19 |
Correct |
131 ms |
10316 KB |
Output is correct |
20 |
Correct |
10 ms |
1368 KB |
Output is correct |
21 |
Correct |
7 ms |
1112 KB |
Output is correct |
22 |
Correct |
7 ms |
1112 KB |
Output is correct |
23 |
Correct |
2987 ms |
125900 KB |
Output is correct |
24 |
Correct |
2199 ms |
104292 KB |
Output is correct |
25 |
Correct |
4 ms |
856 KB |
Output is correct |
26 |
Correct |
10 ms |
1352 KB |
Output is correct |
27 |
Correct |
12 ms |
1448 KB |
Output is correct |
28 |
Correct |
8 ms |
1112 KB |
Output is correct |
29 |
Correct |
8 ms |
1112 KB |
Output is correct |
30 |
Correct |
8 ms |
1112 KB |
Output is correct |
31 |
Correct |
7 ms |
1092 KB |
Output is correct |
32 |
Correct |
2946 ms |
125936 KB |
Output is correct |
33 |
Correct |
2919 ms |
125776 KB |
Output is correct |
34 |
Correct |
2390 ms |
111184 KB |
Output is correct |
35 |
Correct |
2659 ms |
117316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
5 ms |
856 KB |
Output is correct |
3 |
Correct |
4 ms |
856 KB |
Output is correct |
4 |
Correct |
3 ms |
600 KB |
Output is correct |
5 |
Correct |
4 ms |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
3 ms |
600 KB |
Output is correct |
8 |
Correct |
15 ms |
2168 KB |
Output is correct |
9 |
Correct |
78 ms |
6916 KB |
Output is correct |
10 |
Correct |
9 ms |
1368 KB |
Output is correct |
11 |
Correct |
53 ms |
5240 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
399 ms |
23396 KB |
Output is correct |
14 |
Correct |
197 ms |
14416 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
4 ms |
856 KB |
Output is correct |
17 |
Correct |
2 ms |
492 KB |
Output is correct |
18 |
Correct |
44 ms |
4432 KB |
Output is correct |
19 |
Correct |
131 ms |
10316 KB |
Output is correct |
20 |
Correct |
10 ms |
1368 KB |
Output is correct |
21 |
Correct |
7 ms |
1112 KB |
Output is correct |
22 |
Correct |
7 ms |
1112 KB |
Output is correct |
23 |
Correct |
2987 ms |
125900 KB |
Output is correct |
24 |
Correct |
2199 ms |
104292 KB |
Output is correct |
25 |
Correct |
4 ms |
856 KB |
Output is correct |
26 |
Correct |
10 ms |
1352 KB |
Output is correct |
27 |
Correct |
12 ms |
1448 KB |
Output is correct |
28 |
Correct |
8 ms |
1112 KB |
Output is correct |
29 |
Correct |
8 ms |
1112 KB |
Output is correct |
30 |
Correct |
8 ms |
1112 KB |
Output is correct |
31 |
Correct |
7 ms |
1092 KB |
Output is correct |
32 |
Correct |
2946 ms |
125936 KB |
Output is correct |
33 |
Correct |
2919 ms |
125776 KB |
Output is correct |
34 |
Correct |
2390 ms |
111184 KB |
Output is correct |
35 |
Correct |
2659 ms |
117316 KB |
Output is correct |
36 |
Correct |
151 ms |
15440 KB |
Output is correct |
37 |
Correct |
322 ms |
30152 KB |
Output is correct |
38 |
Correct |
110 ms |
12744 KB |
Output is correct |
39 |
Correct |
196 ms |
20568 KB |
Output is correct |
40 |
Correct |
79 ms |
9416 KB |
Output is correct |
41 |
Correct |
623 ms |
51988 KB |
Output is correct |
42 |
Correct |
16 ms |
3792 KB |
Output is correct |
43 |
Execution timed out |
4075 ms |
180176 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4019 ms |
66904 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4043 ms |
19624 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
5 ms |
856 KB |
Output is correct |
3 |
Correct |
4 ms |
856 KB |
Output is correct |
4 |
Correct |
3 ms |
600 KB |
Output is correct |
5 |
Correct |
4 ms |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
3 ms |
600 KB |
Output is correct |
8 |
Correct |
15 ms |
2168 KB |
Output is correct |
9 |
Correct |
78 ms |
6916 KB |
Output is correct |
10 |
Correct |
9 ms |
1368 KB |
Output is correct |
11 |
Correct |
53 ms |
5240 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
399 ms |
23396 KB |
Output is correct |
14 |
Correct |
197 ms |
14416 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
4 ms |
856 KB |
Output is correct |
17 |
Correct |
2 ms |
492 KB |
Output is correct |
18 |
Correct |
44 ms |
4432 KB |
Output is correct |
19 |
Correct |
131 ms |
10316 KB |
Output is correct |
20 |
Correct |
10 ms |
1368 KB |
Output is correct |
21 |
Correct |
7 ms |
1112 KB |
Output is correct |
22 |
Correct |
7 ms |
1112 KB |
Output is correct |
23 |
Correct |
2987 ms |
125900 KB |
Output is correct |
24 |
Correct |
2199 ms |
104292 KB |
Output is correct |
25 |
Correct |
4 ms |
856 KB |
Output is correct |
26 |
Correct |
10 ms |
1352 KB |
Output is correct |
27 |
Correct |
12 ms |
1448 KB |
Output is correct |
28 |
Correct |
8 ms |
1112 KB |
Output is correct |
29 |
Correct |
8 ms |
1112 KB |
Output is correct |
30 |
Correct |
8 ms |
1112 KB |
Output is correct |
31 |
Correct |
7 ms |
1092 KB |
Output is correct |
32 |
Correct |
2946 ms |
125936 KB |
Output is correct |
33 |
Correct |
2919 ms |
125776 KB |
Output is correct |
34 |
Correct |
2390 ms |
111184 KB |
Output is correct |
35 |
Correct |
2659 ms |
117316 KB |
Output is correct |
36 |
Correct |
151 ms |
15440 KB |
Output is correct |
37 |
Correct |
322 ms |
30152 KB |
Output is correct |
38 |
Correct |
110 ms |
12744 KB |
Output is correct |
39 |
Correct |
196 ms |
20568 KB |
Output is correct |
40 |
Correct |
79 ms |
9416 KB |
Output is correct |
41 |
Correct |
623 ms |
51988 KB |
Output is correct |
42 |
Correct |
16 ms |
3792 KB |
Output is correct |
43 |
Execution timed out |
4075 ms |
180176 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4062 ms |
168388 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |