// In the name of Allah
#include <bits/stdc++.h>
#include "towers.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
#define len(x) ((ll) (x).size())
#define Mp make_pair
#define pb push_back
#define endl '\n'
#define sep ' '
const int maxn = 1e5 + 7;
const ll oo = 1e9 + 7;
int n;
ll Ax[maxn], A[maxn]; set<int> st;
int arr[maxn];
bool cmp(int i, int j) {
return (A[i] < A[j]);
}
void init(int N, vector<int> H) {
n = N;
for (int i = 0; i < n; i++) Ax[i] = H[i];
}
bool check(int i, int j, int D) {
if (j - i + 1 <= 2) return 0;
int mx = *max_element(A + i + 1, A + j);
return (mx >= max(A[i], A[j]) + D);
}
bool ok(int i, int D) {
auto it = st.lower_bound(i);
if (it != st.end()) {
if (!check(i, *it, D)) return 0;
}
if (it != st.begin()) {
it--;
if (!check(*it, i, D)) return 0;
}
return 1;
}
int max_towers(int L, int R, int D) {
for (int j = L; j <= R; j++) A[j - L] = Ax[j];
n = R - L + 1;
st.clear();
iota(arr, arr + n, 0); sort(arr, arr + n, cmp);
for (int j = 0; j < n; j++) {
int i = arr[j];
if (ok(i, D)) st.insert(i);
}
return len(st);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4073 ms |
1700 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
456 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
2 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
0 ms |
344 KB |
Output is correct |
26 |
Correct |
0 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
344 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
0 ms |
344 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Correct |
2 ms |
344 KB |
Output is correct |
33 |
Correct |
2 ms |
344 KB |
Output is correct |
34 |
Correct |
1 ms |
344 KB |
Output is correct |
35 |
Correct |
1 ms |
496 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
456 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
2 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
0 ms |
344 KB |
Output is correct |
26 |
Correct |
0 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
344 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
0 ms |
344 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Correct |
2 ms |
344 KB |
Output is correct |
33 |
Correct |
2 ms |
344 KB |
Output is correct |
34 |
Correct |
1 ms |
344 KB |
Output is correct |
35 |
Correct |
1 ms |
496 KB |
Output is correct |
36 |
Correct |
13 ms |
1476 KB |
Output is correct |
37 |
Correct |
14 ms |
1984 KB |
Output is correct |
38 |
Correct |
9 ms |
1880 KB |
Output is correct |
39 |
Correct |
20 ms |
1928 KB |
Output is correct |
40 |
Correct |
11 ms |
2000 KB |
Output is correct |
41 |
Correct |
31 ms |
3272 KB |
Output is correct |
42 |
Correct |
8 ms |
1880 KB |
Output is correct |
43 |
Correct |
729 ms |
1992 KB |
Output is correct |
44 |
Correct |
62 ms |
1880 KB |
Output is correct |
45 |
Correct |
9 ms |
1880 KB |
Output is correct |
46 |
Correct |
12 ms |
1976 KB |
Output is correct |
47 |
Correct |
14 ms |
2512 KB |
Output is correct |
48 |
Correct |
18 ms |
2248 KB |
Output is correct |
49 |
Correct |
8 ms |
1880 KB |
Output is correct |
50 |
Correct |
137 ms |
1980 KB |
Output is correct |
51 |
Correct |
241 ms |
2000 KB |
Output is correct |
52 |
Correct |
34 ms |
4124 KB |
Output is correct |
53 |
Correct |
36 ms |
5076 KB |
Output is correct |
54 |
Correct |
36 ms |
5064 KB |
Output is correct |
55 |
Correct |
2910 ms |
2768 KB |
Output is correct |
56 |
Correct |
1527 ms |
2772 KB |
Output is correct |
57 |
Correct |
43 ms |
3036 KB |
Output is correct |
58 |
Correct |
31 ms |
3576 KB |
Output is correct |
59 |
Correct |
33 ms |
3820 KB |
Output is correct |
60 |
Correct |
48 ms |
5064 KB |
Output is correct |
61 |
Correct |
47 ms |
4736 KB |
Output is correct |
62 |
Correct |
38 ms |
4068 KB |
Output is correct |
63 |
Correct |
35 ms |
4560 KB |
Output is correct |
64 |
Correct |
3013 ms |
2768 KB |
Output is correct |
65 |
Correct |
3008 ms |
2772 KB |
Output is correct |
66 |
Correct |
929 ms |
2768 KB |
Output is correct |
67 |
Correct |
2802 ms |
2768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4027 ms |
4048 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4037 ms |
1360 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
456 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
2 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
0 ms |
344 KB |
Output is correct |
26 |
Correct |
0 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
344 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
0 ms |
344 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Correct |
2 ms |
344 KB |
Output is correct |
33 |
Correct |
2 ms |
344 KB |
Output is correct |
34 |
Correct |
1 ms |
344 KB |
Output is correct |
35 |
Correct |
1 ms |
496 KB |
Output is correct |
36 |
Correct |
13 ms |
1476 KB |
Output is correct |
37 |
Correct |
14 ms |
1984 KB |
Output is correct |
38 |
Correct |
9 ms |
1880 KB |
Output is correct |
39 |
Correct |
20 ms |
1928 KB |
Output is correct |
40 |
Correct |
11 ms |
2000 KB |
Output is correct |
41 |
Correct |
31 ms |
3272 KB |
Output is correct |
42 |
Correct |
8 ms |
1880 KB |
Output is correct |
43 |
Correct |
729 ms |
1992 KB |
Output is correct |
44 |
Correct |
62 ms |
1880 KB |
Output is correct |
45 |
Correct |
9 ms |
1880 KB |
Output is correct |
46 |
Correct |
12 ms |
1976 KB |
Output is correct |
47 |
Correct |
14 ms |
2512 KB |
Output is correct |
48 |
Correct |
18 ms |
2248 KB |
Output is correct |
49 |
Correct |
8 ms |
1880 KB |
Output is correct |
50 |
Correct |
137 ms |
1980 KB |
Output is correct |
51 |
Correct |
241 ms |
2000 KB |
Output is correct |
52 |
Correct |
34 ms |
4124 KB |
Output is correct |
53 |
Correct |
36 ms |
5076 KB |
Output is correct |
54 |
Correct |
36 ms |
5064 KB |
Output is correct |
55 |
Correct |
2910 ms |
2768 KB |
Output is correct |
56 |
Correct |
1527 ms |
2772 KB |
Output is correct |
57 |
Correct |
43 ms |
3036 KB |
Output is correct |
58 |
Correct |
31 ms |
3576 KB |
Output is correct |
59 |
Correct |
33 ms |
3820 KB |
Output is correct |
60 |
Correct |
48 ms |
5064 KB |
Output is correct |
61 |
Correct |
47 ms |
4736 KB |
Output is correct |
62 |
Correct |
38 ms |
4068 KB |
Output is correct |
63 |
Correct |
35 ms |
4560 KB |
Output is correct |
64 |
Correct |
3013 ms |
2768 KB |
Output is correct |
65 |
Correct |
3008 ms |
2772 KB |
Output is correct |
66 |
Correct |
929 ms |
2768 KB |
Output is correct |
67 |
Correct |
2802 ms |
2768 KB |
Output is correct |
68 |
Execution timed out |
4027 ms |
4048 KB |
Time limit exceeded |
69 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4073 ms |
1700 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |