#include "towers.h"
#include <bits/stdc++.h>
using namespace std;
const int INF=2e9;
int l[100001],r[100001],a[100001],b[100001];
stack <int> st;
void init(int N, vector <int> H){
for (int i=0;i<N;i++){
a[i]=b[i]=H[i];
r[i]=N-1;
while (!st.empty()&&H[st.top()]>H[i]){
r[st.top()]=i-1;
a[i]=max(a[i],a[st.top()]);
int x=b[st.top()];
st.pop();
if (!st.empty())
b[st.top()]=max(b[st.top()],x);
}
l[i]=(st.empty()?0:st.top()+1);
st.push(i);
}
for (int i=0;i<N;i++){
a[i]-=H[i];
b[i]-=H[i];
l[i]--;
r[i]++;
}
}
int max_towers(int L, int R, int D){
int res=0;
for (int i=L;i<=R;i++){
int x=INF,y=INF;
if (l[i]>=L)
x=a[i];
if (r[i]<=R)
y=b[i];
res+=(min(x,y)>=D);
}
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1365 ms |
1968 KB |
Output is correct |
2 |
Execution timed out |
4041 ms |
3148 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
344 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 |
0 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 |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
500 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
0 ms |
344 KB |
Output is correct |
24 |
Correct |
0 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 |
0 ms |
344 KB |
Output is correct |
28 |
Correct |
0 ms |
344 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
0 ms |
344 KB |
Output is correct |
31 |
Correct |
0 ms |
344 KB |
Output is correct |
32 |
Correct |
0 ms |
344 KB |
Output is correct |
33 |
Correct |
1 ms |
344 KB |
Output is correct |
34 |
Correct |
0 ms |
344 KB |
Output is correct |
35 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
344 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 |
0 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 |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
500 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
0 ms |
344 KB |
Output is correct |
24 |
Correct |
0 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 |
0 ms |
344 KB |
Output is correct |
28 |
Correct |
0 ms |
344 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
0 ms |
344 KB |
Output is correct |
31 |
Correct |
0 ms |
344 KB |
Output is correct |
32 |
Correct |
0 ms |
344 KB |
Output is correct |
33 |
Correct |
1 ms |
344 KB |
Output is correct |
34 |
Correct |
0 ms |
344 KB |
Output is correct |
35 |
Correct |
1 ms |
596 KB |
Output is correct |
36 |
Correct |
7 ms |
1984 KB |
Output is correct |
37 |
Correct |
10 ms |
2632 KB |
Output is correct |
38 |
Correct |
10 ms |
2708 KB |
Output is correct |
39 |
Correct |
10 ms |
2628 KB |
Output is correct |
40 |
Correct |
13 ms |
2632 KB |
Output is correct |
41 |
Correct |
14 ms |
2640 KB |
Output is correct |
42 |
Correct |
10 ms |
2636 KB |
Output is correct |
43 |
Correct |
9 ms |
3312 KB |
Output is correct |
44 |
Correct |
10 ms |
2632 KB |
Output is correct |
45 |
Correct |
14 ms |
2868 KB |
Output is correct |
46 |
Correct |
9 ms |
2632 KB |
Output is correct |
47 |
Correct |
13 ms |
2628 KB |
Output is correct |
48 |
Correct |
12 ms |
2624 KB |
Output is correct |
49 |
Correct |
10 ms |
2624 KB |
Output is correct |
50 |
Correct |
14 ms |
2636 KB |
Output is correct |
51 |
Correct |
13 ms |
3312 KB |
Output is correct |
52 |
Correct |
12 ms |
2612 KB |
Output is correct |
53 |
Correct |
10 ms |
2648 KB |
Output is correct |
54 |
Correct |
10 ms |
2632 KB |
Output is correct |
55 |
Correct |
13 ms |
2636 KB |
Output is correct |
56 |
Correct |
11 ms |
2900 KB |
Output is correct |
57 |
Correct |
10 ms |
2620 KB |
Output is correct |
58 |
Correct |
13 ms |
2632 KB |
Output is correct |
59 |
Correct |
10 ms |
2676 KB |
Output is correct |
60 |
Correct |
10 ms |
2632 KB |
Output is correct |
61 |
Correct |
16 ms |
2636 KB |
Output is correct |
62 |
Correct |
10 ms |
2632 KB |
Output is correct |
63 |
Correct |
10 ms |
2624 KB |
Output is correct |
64 |
Correct |
9 ms |
3144 KB |
Output is correct |
65 |
Correct |
9 ms |
2632 KB |
Output is correct |
66 |
Correct |
11 ms |
2888 KB |
Output is correct |
67 |
Correct |
14 ms |
2628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3625 ms |
2628 KB |
Output is correct |
2 |
Execution timed out |
4046 ms |
2632 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1102 ms |
1008 KB |
Output is correct |
2 |
Execution timed out |
4037 ms |
2632 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
344 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 |
0 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 |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
500 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
0 ms |
344 KB |
Output is correct |
24 |
Correct |
0 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 |
0 ms |
344 KB |
Output is correct |
28 |
Correct |
0 ms |
344 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
0 ms |
344 KB |
Output is correct |
31 |
Correct |
0 ms |
344 KB |
Output is correct |
32 |
Correct |
0 ms |
344 KB |
Output is correct |
33 |
Correct |
1 ms |
344 KB |
Output is correct |
34 |
Correct |
0 ms |
344 KB |
Output is correct |
35 |
Correct |
1 ms |
596 KB |
Output is correct |
36 |
Correct |
7 ms |
1984 KB |
Output is correct |
37 |
Correct |
10 ms |
2632 KB |
Output is correct |
38 |
Correct |
10 ms |
2708 KB |
Output is correct |
39 |
Correct |
10 ms |
2628 KB |
Output is correct |
40 |
Correct |
13 ms |
2632 KB |
Output is correct |
41 |
Correct |
14 ms |
2640 KB |
Output is correct |
42 |
Correct |
10 ms |
2636 KB |
Output is correct |
43 |
Correct |
9 ms |
3312 KB |
Output is correct |
44 |
Correct |
10 ms |
2632 KB |
Output is correct |
45 |
Correct |
14 ms |
2868 KB |
Output is correct |
46 |
Correct |
9 ms |
2632 KB |
Output is correct |
47 |
Correct |
13 ms |
2628 KB |
Output is correct |
48 |
Correct |
12 ms |
2624 KB |
Output is correct |
49 |
Correct |
10 ms |
2624 KB |
Output is correct |
50 |
Correct |
14 ms |
2636 KB |
Output is correct |
51 |
Correct |
13 ms |
3312 KB |
Output is correct |
52 |
Correct |
12 ms |
2612 KB |
Output is correct |
53 |
Correct |
10 ms |
2648 KB |
Output is correct |
54 |
Correct |
10 ms |
2632 KB |
Output is correct |
55 |
Correct |
13 ms |
2636 KB |
Output is correct |
56 |
Correct |
11 ms |
2900 KB |
Output is correct |
57 |
Correct |
10 ms |
2620 KB |
Output is correct |
58 |
Correct |
13 ms |
2632 KB |
Output is correct |
59 |
Correct |
10 ms |
2676 KB |
Output is correct |
60 |
Correct |
10 ms |
2632 KB |
Output is correct |
61 |
Correct |
16 ms |
2636 KB |
Output is correct |
62 |
Correct |
10 ms |
2632 KB |
Output is correct |
63 |
Correct |
10 ms |
2624 KB |
Output is correct |
64 |
Correct |
9 ms |
3144 KB |
Output is correct |
65 |
Correct |
9 ms |
2632 KB |
Output is correct |
66 |
Correct |
11 ms |
2888 KB |
Output is correct |
67 |
Correct |
14 ms |
2628 KB |
Output is correct |
68 |
Correct |
3625 ms |
2628 KB |
Output is correct |
69 |
Execution timed out |
4046 ms |
2632 KB |
Time limit exceeded |
70 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1365 ms |
1968 KB |
Output is correct |
2 |
Execution timed out |
4041 ms |
3148 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |