#include <bits/stdc++.h>
#include "towers.h"
using namespace std;
const int N = 1e5 + 10 , inf = 1e9 , Lg = 17;
int n , a[N] , rmxq[N][Lg] , rmnq[N][Lg] , lg2[N];
int mn_pos(int aa , int bb)
{
if(a[aa] < a[bb])
return aa;
return bb;
}
int mx_pos(int aa , int bb)
{
if(a[aa] > a[bb])
return aa;
return bb;
}
void Build()
{
lg2[1] = 0;
for(int i = 2 ; i < N ; i++)
lg2[i] = lg2[i / 2] + 1;
for(int i = 0 ; i < n ; i++)
rmnq[i][0] = rmxq[i][0] = i;
for(int j = 1 ; j < Lg ; j++)
{
int len = (1 << j);
for(int i = 0 ; i + len <= n ; i++)
{
rmnq[i][j] = mn_pos(rmnq[i][j - 1] , rmnq[i + len / 2][j - 1]);
rmxq[i][j] = mx_pos(rmxq[i][j - 1] , rmxq[i + len / 2][j - 1]);
}
}
}
int Get_mx(int l , int r)
{
r++;
int sz = (r - l); sz = lg2[sz];
return mx_pos(rmxq[l][sz] , rmxq[r - (1 << sz)][sz]);
}
int Get_mn(int l , int r)
{
r++;
int sz = (r - l); sz = lg2[sz];
return mn_pos(rmnq[l][sz] , rmnq[r - (1 << sz)][sz]);
}
void init(int nn , vector <int> vec)
{
n = nn;
for(int i = 0 ; i < n ; i++)
a[i] = vec[i];
Build();
}
int Solve(int l , int r , int d , int val)
{
if(l > r)
return 0;
int mn = a[Get_mn(l , r)];
int pos_mx = Get_mx(l , r);
if(mn > val)
return 0;
int res = max(1 , Solve(l , pos_mx - 1 , d , a[pos_mx] - d) + Solve(pos_mx + 1 , r , d , a[pos_mx] - d));
return res;
}
int max_towers(int l , int r , int d)
{
return Solve(l , r , d , inf);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2995 ms |
15836 KB |
Output is correct |
2 |
Execution timed out |
4002 ms |
19228 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4696 KB |
Output is correct |
2 |
Correct |
1 ms |
4696 KB |
Output is correct |
3 |
Correct |
1 ms |
4696 KB |
Output is correct |
4 |
Correct |
1 ms |
4696 KB |
Output is correct |
5 |
Correct |
1 ms |
4696 KB |
Output is correct |
6 |
Correct |
1 ms |
4696 KB |
Output is correct |
7 |
Correct |
1 ms |
4696 KB |
Output is correct |
8 |
Correct |
1 ms |
4696 KB |
Output is correct |
9 |
Correct |
1 ms |
4696 KB |
Output is correct |
10 |
Correct |
1 ms |
4696 KB |
Output is correct |
11 |
Correct |
1 ms |
4696 KB |
Output is correct |
12 |
Correct |
1 ms |
4696 KB |
Output is correct |
13 |
Correct |
1 ms |
4696 KB |
Output is correct |
14 |
Correct |
1 ms |
4696 KB |
Output is correct |
15 |
Correct |
1 ms |
4696 KB |
Output is correct |
16 |
Correct |
1 ms |
4696 KB |
Output is correct |
17 |
Correct |
1 ms |
4696 KB |
Output is correct |
18 |
Correct |
1 ms |
4696 KB |
Output is correct |
19 |
Correct |
1 ms |
4744 KB |
Output is correct |
20 |
Correct |
1 ms |
4696 KB |
Output is correct |
21 |
Correct |
1 ms |
4696 KB |
Output is correct |
22 |
Correct |
1 ms |
4696 KB |
Output is correct |
23 |
Correct |
1 ms |
4696 KB |
Output is correct |
24 |
Correct |
1 ms |
4696 KB |
Output is correct |
25 |
Correct |
1 ms |
4696 KB |
Output is correct |
26 |
Correct |
1 ms |
4696 KB |
Output is correct |
27 |
Correct |
1 ms |
4696 KB |
Output is correct |
28 |
Correct |
1 ms |
4696 KB |
Output is correct |
29 |
Correct |
1 ms |
4696 KB |
Output is correct |
30 |
Correct |
1 ms |
4696 KB |
Output is correct |
31 |
Correct |
1 ms |
4696 KB |
Output is correct |
32 |
Correct |
1 ms |
4696 KB |
Output is correct |
33 |
Correct |
1 ms |
4696 KB |
Output is correct |
34 |
Correct |
1 ms |
4696 KB |
Output is correct |
35 |
Correct |
1 ms |
4696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4696 KB |
Output is correct |
2 |
Correct |
1 ms |
4696 KB |
Output is correct |
3 |
Correct |
1 ms |
4696 KB |
Output is correct |
4 |
Correct |
1 ms |
4696 KB |
Output is correct |
5 |
Correct |
1 ms |
4696 KB |
Output is correct |
6 |
Correct |
1 ms |
4696 KB |
Output is correct |
7 |
Correct |
1 ms |
4696 KB |
Output is correct |
8 |
Correct |
1 ms |
4696 KB |
Output is correct |
9 |
Correct |
1 ms |
4696 KB |
Output is correct |
10 |
Correct |
1 ms |
4696 KB |
Output is correct |
11 |
Correct |
1 ms |
4696 KB |
Output is correct |
12 |
Correct |
1 ms |
4696 KB |
Output is correct |
13 |
Correct |
1 ms |
4696 KB |
Output is correct |
14 |
Correct |
1 ms |
4696 KB |
Output is correct |
15 |
Correct |
1 ms |
4696 KB |
Output is correct |
16 |
Correct |
1 ms |
4696 KB |
Output is correct |
17 |
Correct |
1 ms |
4696 KB |
Output is correct |
18 |
Correct |
1 ms |
4696 KB |
Output is correct |
19 |
Correct |
1 ms |
4744 KB |
Output is correct |
20 |
Correct |
1 ms |
4696 KB |
Output is correct |
21 |
Correct |
1 ms |
4696 KB |
Output is correct |
22 |
Correct |
1 ms |
4696 KB |
Output is correct |
23 |
Correct |
1 ms |
4696 KB |
Output is correct |
24 |
Correct |
1 ms |
4696 KB |
Output is correct |
25 |
Correct |
1 ms |
4696 KB |
Output is correct |
26 |
Correct |
1 ms |
4696 KB |
Output is correct |
27 |
Correct |
1 ms |
4696 KB |
Output is correct |
28 |
Correct |
1 ms |
4696 KB |
Output is correct |
29 |
Correct |
1 ms |
4696 KB |
Output is correct |
30 |
Correct |
1 ms |
4696 KB |
Output is correct |
31 |
Correct |
1 ms |
4696 KB |
Output is correct |
32 |
Correct |
1 ms |
4696 KB |
Output is correct |
33 |
Correct |
1 ms |
4696 KB |
Output is correct |
34 |
Correct |
1 ms |
4696 KB |
Output is correct |
35 |
Correct |
1 ms |
4696 KB |
Output is correct |
36 |
Correct |
9 ms |
13656 KB |
Output is correct |
37 |
Correct |
13 ms |
15192 KB |
Output is correct |
38 |
Correct |
13 ms |
15192 KB |
Output is correct |
39 |
Correct |
12 ms |
15192 KB |
Output is correct |
40 |
Correct |
18 ms |
15184 KB |
Output is correct |
41 |
Correct |
13 ms |
15192 KB |
Output is correct |
42 |
Correct |
13 ms |
15192 KB |
Output is correct |
43 |
Correct |
13 ms |
16332 KB |
Output is correct |
44 |
Correct |
18 ms |
15192 KB |
Output is correct |
45 |
Correct |
14 ms |
15192 KB |
Output is correct |
46 |
Correct |
18 ms |
15176 KB |
Output is correct |
47 |
Correct |
13 ms |
15192 KB |
Output is correct |
48 |
Correct |
18 ms |
15192 KB |
Output is correct |
49 |
Correct |
13 ms |
15192 KB |
Output is correct |
50 |
Correct |
13 ms |
15876 KB |
Output is correct |
51 |
Correct |
19 ms |
16592 KB |
Output is correct |
52 |
Correct |
14 ms |
15320 KB |
Output is correct |
53 |
Correct |
13 ms |
15192 KB |
Output is correct |
54 |
Correct |
14 ms |
15192 KB |
Output is correct |
55 |
Correct |
16 ms |
19388 KB |
Output is correct |
56 |
Correct |
21 ms |
19152 KB |
Output is correct |
57 |
Correct |
13 ms |
15032 KB |
Output is correct |
58 |
Correct |
17 ms |
15136 KB |
Output is correct |
59 |
Correct |
14 ms |
15192 KB |
Output is correct |
60 |
Correct |
13 ms |
15180 KB |
Output is correct |
61 |
Correct |
15 ms |
15192 KB |
Output is correct |
62 |
Correct |
14 ms |
15316 KB |
Output is correct |
63 |
Correct |
14 ms |
15192 KB |
Output is correct |
64 |
Correct |
14 ms |
17104 KB |
Output is correct |
65 |
Correct |
14 ms |
16976 KB |
Output is correct |
66 |
Correct |
14 ms |
16592 KB |
Output is correct |
67 |
Correct |
14 ms |
16848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4073 ms |
15192 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4002 ms |
7000 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4696 KB |
Output is correct |
2 |
Correct |
1 ms |
4696 KB |
Output is correct |
3 |
Correct |
1 ms |
4696 KB |
Output is correct |
4 |
Correct |
1 ms |
4696 KB |
Output is correct |
5 |
Correct |
1 ms |
4696 KB |
Output is correct |
6 |
Correct |
1 ms |
4696 KB |
Output is correct |
7 |
Correct |
1 ms |
4696 KB |
Output is correct |
8 |
Correct |
1 ms |
4696 KB |
Output is correct |
9 |
Correct |
1 ms |
4696 KB |
Output is correct |
10 |
Correct |
1 ms |
4696 KB |
Output is correct |
11 |
Correct |
1 ms |
4696 KB |
Output is correct |
12 |
Correct |
1 ms |
4696 KB |
Output is correct |
13 |
Correct |
1 ms |
4696 KB |
Output is correct |
14 |
Correct |
1 ms |
4696 KB |
Output is correct |
15 |
Correct |
1 ms |
4696 KB |
Output is correct |
16 |
Correct |
1 ms |
4696 KB |
Output is correct |
17 |
Correct |
1 ms |
4696 KB |
Output is correct |
18 |
Correct |
1 ms |
4696 KB |
Output is correct |
19 |
Correct |
1 ms |
4744 KB |
Output is correct |
20 |
Correct |
1 ms |
4696 KB |
Output is correct |
21 |
Correct |
1 ms |
4696 KB |
Output is correct |
22 |
Correct |
1 ms |
4696 KB |
Output is correct |
23 |
Correct |
1 ms |
4696 KB |
Output is correct |
24 |
Correct |
1 ms |
4696 KB |
Output is correct |
25 |
Correct |
1 ms |
4696 KB |
Output is correct |
26 |
Correct |
1 ms |
4696 KB |
Output is correct |
27 |
Correct |
1 ms |
4696 KB |
Output is correct |
28 |
Correct |
1 ms |
4696 KB |
Output is correct |
29 |
Correct |
1 ms |
4696 KB |
Output is correct |
30 |
Correct |
1 ms |
4696 KB |
Output is correct |
31 |
Correct |
1 ms |
4696 KB |
Output is correct |
32 |
Correct |
1 ms |
4696 KB |
Output is correct |
33 |
Correct |
1 ms |
4696 KB |
Output is correct |
34 |
Correct |
1 ms |
4696 KB |
Output is correct |
35 |
Correct |
1 ms |
4696 KB |
Output is correct |
36 |
Correct |
9 ms |
13656 KB |
Output is correct |
37 |
Correct |
13 ms |
15192 KB |
Output is correct |
38 |
Correct |
13 ms |
15192 KB |
Output is correct |
39 |
Correct |
12 ms |
15192 KB |
Output is correct |
40 |
Correct |
18 ms |
15184 KB |
Output is correct |
41 |
Correct |
13 ms |
15192 KB |
Output is correct |
42 |
Correct |
13 ms |
15192 KB |
Output is correct |
43 |
Correct |
13 ms |
16332 KB |
Output is correct |
44 |
Correct |
18 ms |
15192 KB |
Output is correct |
45 |
Correct |
14 ms |
15192 KB |
Output is correct |
46 |
Correct |
18 ms |
15176 KB |
Output is correct |
47 |
Correct |
13 ms |
15192 KB |
Output is correct |
48 |
Correct |
18 ms |
15192 KB |
Output is correct |
49 |
Correct |
13 ms |
15192 KB |
Output is correct |
50 |
Correct |
13 ms |
15876 KB |
Output is correct |
51 |
Correct |
19 ms |
16592 KB |
Output is correct |
52 |
Correct |
14 ms |
15320 KB |
Output is correct |
53 |
Correct |
13 ms |
15192 KB |
Output is correct |
54 |
Correct |
14 ms |
15192 KB |
Output is correct |
55 |
Correct |
16 ms |
19388 KB |
Output is correct |
56 |
Correct |
21 ms |
19152 KB |
Output is correct |
57 |
Correct |
13 ms |
15032 KB |
Output is correct |
58 |
Correct |
17 ms |
15136 KB |
Output is correct |
59 |
Correct |
14 ms |
15192 KB |
Output is correct |
60 |
Correct |
13 ms |
15180 KB |
Output is correct |
61 |
Correct |
15 ms |
15192 KB |
Output is correct |
62 |
Correct |
14 ms |
15316 KB |
Output is correct |
63 |
Correct |
14 ms |
15192 KB |
Output is correct |
64 |
Correct |
14 ms |
17104 KB |
Output is correct |
65 |
Correct |
14 ms |
16976 KB |
Output is correct |
66 |
Correct |
14 ms |
16592 KB |
Output is correct |
67 |
Correct |
14 ms |
16848 KB |
Output is correct |
68 |
Execution timed out |
4073 ms |
15192 KB |
Time limit exceeded |
69 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2995 ms |
15836 KB |
Output is correct |
2 |
Execution timed out |
4002 ms |
19228 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |