#include "towers.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> h;
int n;
void init(int N, vector<int> H) {
n = N;
h = H;
}
bool processed = false;
vector<int> nxt, dow;
int max_towers(int l, int r, int D) {
if (!processed) {
processed = true;
deque<pair<int, int>> st;
nxt.assign(n + 1, n);
dow.assign(n + 1, n);
for (int i = n - 1; i >= 0; i--) {
while (!st.empty() && h[st.front().second] <= h[i]) st.pop_front();
st.push_front({h[i], i});
auto p = lower_bound(st.begin(), st.end(), pair{h[i] + D, -1});
if (p != st.end()) {
nxt[i] = p->second;
}
}
for (int i = n - 2; i >= 0; i--) {
nxt[i] = min(nxt[i], nxt[i + 1]);
}
st.clear();
for (int i = n - 1; i >= 0; i--) {
while (!st.empty() && h[st.back().second] >= h[i]) st.pop_back();
st.push_back({h[i], i});
auto p = lower_bound(st.begin(), st.end(), pair{h[i] - D + 1, -1});
if (p != st.begin()) {
p--;
dow[i] = p->second;
}
// if (i == 2) {
// cout << "the demosntration\n";
// for (auto [x, y] : st) {
// cout << x << " ";
// }
// cout << "\n";
// }
}
for (int i = n - 2; i >= 0; i--) {
dow[i] = min(dow[i], dow[i + 1]);
}
}
// for (int i = 0; i < n; i++) {
// cout << nxt[i] << " " << dow[i] << "\n";
// }
int p = l;
int s = 0;
while (p < r) {
if (s % 2 == 0) {
p = nxt[p];
if (p <= r) {
s++;
}
} else {
p = dow[p];
if (p <= r) {
s++;
}
}
}
return s / 2 + 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
275 ms |
1656 KB |
31st lines differ - on the 1st token, expected: '1', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 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 |
384 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 |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
0 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 |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
208 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 |
208 KB |
Output is correct |
21 |
Correct |
1 ms |
208 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
208 KB |
Output is correct |
26 |
Correct |
1 ms |
208 KB |
Output is correct |
27 |
Correct |
1 ms |
208 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
208 KB |
Output is correct |
30 |
Correct |
1 ms |
208 KB |
Output is correct |
31 |
Correct |
1 ms |
208 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 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 |
384 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 |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
0 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 |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
208 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 |
208 KB |
Output is correct |
21 |
Correct |
1 ms |
208 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
208 KB |
Output is correct |
26 |
Correct |
1 ms |
208 KB |
Output is correct |
27 |
Correct |
1 ms |
208 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
208 KB |
Output is correct |
30 |
Correct |
1 ms |
208 KB |
Output is correct |
31 |
Correct |
1 ms |
208 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
1 ms |
336 KB |
Output is correct |
36 |
Correct |
11 ms |
1336 KB |
Output is correct |
37 |
Correct |
20 ms |
1860 KB |
Output is correct |
38 |
Correct |
19 ms |
1832 KB |
Output is correct |
39 |
Correct |
13 ms |
1856 KB |
Output is correct |
40 |
Correct |
15 ms |
1864 KB |
Output is correct |
41 |
Correct |
15 ms |
1988 KB |
Output is correct |
42 |
Correct |
13 ms |
1884 KB |
Output is correct |
43 |
Correct |
18 ms |
2632 KB |
Output is correct |
44 |
Correct |
18 ms |
2624 KB |
Output is correct |
45 |
Correct |
16 ms |
2376 KB |
Output is correct |
46 |
Correct |
18 ms |
2376 KB |
Output is correct |
47 |
Correct |
14 ms |
1864 KB |
Output is correct |
48 |
Correct |
19 ms |
1864 KB |
Output is correct |
49 |
Correct |
13 ms |
1824 KB |
Output is correct |
50 |
Correct |
23 ms |
2588 KB |
Output is correct |
51 |
Correct |
14 ms |
2632 KB |
Output is correct |
52 |
Correct |
14 ms |
1864 KB |
Output is correct |
53 |
Correct |
16 ms |
1956 KB |
Output is correct |
54 |
Correct |
19 ms |
1864 KB |
Output is correct |
55 |
Correct |
18 ms |
2632 KB |
Output is correct |
56 |
Correct |
15 ms |
2504 KB |
Output is correct |
57 |
Correct |
15 ms |
1748 KB |
Output is correct |
58 |
Correct |
15 ms |
1864 KB |
Output is correct |
59 |
Correct |
15 ms |
1864 KB |
Output is correct |
60 |
Correct |
20 ms |
1840 KB |
Output is correct |
61 |
Correct |
14 ms |
1864 KB |
Output is correct |
62 |
Correct |
14 ms |
1876 KB |
Output is correct |
63 |
Correct |
15 ms |
1820 KB |
Output is correct |
64 |
Correct |
17 ms |
2632 KB |
Output is correct |
65 |
Correct |
17 ms |
2632 KB |
Output is correct |
66 |
Correct |
23 ms |
2300 KB |
Output is correct |
67 |
Correct |
20 ms |
2632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3649 ms |
1740 KB |
Output is correct |
2 |
Execution timed out |
4037 ms |
1864 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1091 ms |
748 KB |
2nd lines differ - on the 1st token, expected: '7063', found: '7197' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 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 |
384 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 |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
0 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 |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
208 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 |
208 KB |
Output is correct |
21 |
Correct |
1 ms |
208 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
208 KB |
Output is correct |
26 |
Correct |
1 ms |
208 KB |
Output is correct |
27 |
Correct |
1 ms |
208 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
208 KB |
Output is correct |
30 |
Correct |
1 ms |
208 KB |
Output is correct |
31 |
Correct |
1 ms |
208 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
1 ms |
336 KB |
Output is correct |
36 |
Correct |
11 ms |
1336 KB |
Output is correct |
37 |
Correct |
20 ms |
1860 KB |
Output is correct |
38 |
Correct |
19 ms |
1832 KB |
Output is correct |
39 |
Correct |
13 ms |
1856 KB |
Output is correct |
40 |
Correct |
15 ms |
1864 KB |
Output is correct |
41 |
Correct |
15 ms |
1988 KB |
Output is correct |
42 |
Correct |
13 ms |
1884 KB |
Output is correct |
43 |
Correct |
18 ms |
2632 KB |
Output is correct |
44 |
Correct |
18 ms |
2624 KB |
Output is correct |
45 |
Correct |
16 ms |
2376 KB |
Output is correct |
46 |
Correct |
18 ms |
2376 KB |
Output is correct |
47 |
Correct |
14 ms |
1864 KB |
Output is correct |
48 |
Correct |
19 ms |
1864 KB |
Output is correct |
49 |
Correct |
13 ms |
1824 KB |
Output is correct |
50 |
Correct |
23 ms |
2588 KB |
Output is correct |
51 |
Correct |
14 ms |
2632 KB |
Output is correct |
52 |
Correct |
14 ms |
1864 KB |
Output is correct |
53 |
Correct |
16 ms |
1956 KB |
Output is correct |
54 |
Correct |
19 ms |
1864 KB |
Output is correct |
55 |
Correct |
18 ms |
2632 KB |
Output is correct |
56 |
Correct |
15 ms |
2504 KB |
Output is correct |
57 |
Correct |
15 ms |
1748 KB |
Output is correct |
58 |
Correct |
15 ms |
1864 KB |
Output is correct |
59 |
Correct |
15 ms |
1864 KB |
Output is correct |
60 |
Correct |
20 ms |
1840 KB |
Output is correct |
61 |
Correct |
14 ms |
1864 KB |
Output is correct |
62 |
Correct |
14 ms |
1876 KB |
Output is correct |
63 |
Correct |
15 ms |
1820 KB |
Output is correct |
64 |
Correct |
17 ms |
2632 KB |
Output is correct |
65 |
Correct |
17 ms |
2632 KB |
Output is correct |
66 |
Correct |
23 ms |
2300 KB |
Output is correct |
67 |
Correct |
20 ms |
2632 KB |
Output is correct |
68 |
Correct |
3649 ms |
1740 KB |
Output is correct |
69 |
Execution timed out |
4037 ms |
1864 KB |
Time limit exceeded |
70 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
275 ms |
1656 KB |
31st lines differ - on the 1st token, expected: '1', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |