#include "towers.h"
#include <bits/stdc++.h>
using namespace std;
using mim = pair<pair<int,int>,int>;
const int maxn=1e5+10;
const int logg=18;
int n;
int h[maxn];
mim sparse[logg][maxn];
mim comb(mim &a,mim &b){
mim ret=a;
ret.first=max(ret.first,b.first);
ret.second=min(ret.second,b.second);
return ret;
}
void init(int _n, vector<int> _h) {
n=_n;
for(int i=0;i<n;i++) h[i]=_h[i];
for(int i=0;i<logg;i++){
for(int j=0;j<n;j++){
if(i==0) sparse[i][j]={{h[j],j},h[j]};
else if(j-(1<<(i-1))>=0) sparse[i][j]=comb(sparse[i-1][j],sparse[i-1][j-(1<<(i-1))]);
else sparse[i][j]=sparse[i-1][j];
}
}
}
mim qry(int l,int r){
mim ret={{h[l],l},h[l]};
for(int i=logg-1;i>=0;i--){
if(r-(1<<i)+1>=l){
ret=comb(ret,sparse[i][r]);
r-=(1<<i);
}
}
return ret;
}
int resi(int l,int r,int d,int naj=1e9+10){
if(r<l) return 0;
auto temp=qry(l,r);
pair<int,int> maxi=temp.first;
int klk=temp.second<=naj;
return max(resi(l,maxi.second-1,d,maxi.first-d)+resi(maxi.second+1,r,d,maxi.first-d),int(klk>0));
}
int max_towers(int l, int r, int d) {
return resi(l,r,d);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4053 ms |
17264 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
464 KB |
Output is correct |
2 |
Correct |
1 ms |
848 KB |
Output is correct |
3 |
Correct |
1 ms |
848 KB |
Output is correct |
4 |
Correct |
1 ms |
848 KB |
Output is correct |
5 |
Correct |
1 ms |
848 KB |
Output is correct |
6 |
Correct |
1 ms |
848 KB |
Output is correct |
7 |
Correct |
1 ms |
848 KB |
Output is correct |
8 |
Correct |
1 ms |
848 KB |
Output is correct |
9 |
Correct |
1 ms |
848 KB |
Output is correct |
10 |
Correct |
1 ms |
848 KB |
Output is correct |
11 |
Correct |
1 ms |
848 KB |
Output is correct |
12 |
Correct |
0 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
848 KB |
Output is correct |
14 |
Correct |
1 ms |
848 KB |
Output is correct |
15 |
Correct |
1 ms |
848 KB |
Output is correct |
16 |
Correct |
1 ms |
812 KB |
Output is correct |
17 |
Correct |
1 ms |
848 KB |
Output is correct |
18 |
Correct |
1 ms |
848 KB |
Output is correct |
19 |
Correct |
1 ms |
848 KB |
Output is correct |
20 |
Correct |
1 ms |
848 KB |
Output is correct |
21 |
Correct |
1 ms |
848 KB |
Output is correct |
22 |
Correct |
1 ms |
848 KB |
Output is correct |
23 |
Correct |
1 ms |
976 KB |
Output is correct |
24 |
Correct |
1 ms |
976 KB |
Output is correct |
25 |
Correct |
1 ms |
464 KB |
Output is correct |
26 |
Correct |
1 ms |
848 KB |
Output is correct |
27 |
Correct |
1 ms |
848 KB |
Output is correct |
28 |
Correct |
1 ms |
848 KB |
Output is correct |
29 |
Correct |
1 ms |
848 KB |
Output is correct |
30 |
Correct |
1 ms |
848 KB |
Output is correct |
31 |
Correct |
1 ms |
748 KB |
Output is correct |
32 |
Correct |
1 ms |
976 KB |
Output is correct |
33 |
Correct |
1 ms |
976 KB |
Output is correct |
34 |
Correct |
1 ms |
976 KB |
Output is correct |
35 |
Correct |
1 ms |
976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
464 KB |
Output is correct |
2 |
Correct |
1 ms |
848 KB |
Output is correct |
3 |
Correct |
1 ms |
848 KB |
Output is correct |
4 |
Correct |
1 ms |
848 KB |
Output is correct |
5 |
Correct |
1 ms |
848 KB |
Output is correct |
6 |
Correct |
1 ms |
848 KB |
Output is correct |
7 |
Correct |
1 ms |
848 KB |
Output is correct |
8 |
Correct |
1 ms |
848 KB |
Output is correct |
9 |
Correct |
1 ms |
848 KB |
Output is correct |
10 |
Correct |
1 ms |
848 KB |
Output is correct |
11 |
Correct |
1 ms |
848 KB |
Output is correct |
12 |
Correct |
0 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
848 KB |
Output is correct |
14 |
Correct |
1 ms |
848 KB |
Output is correct |
15 |
Correct |
1 ms |
848 KB |
Output is correct |
16 |
Correct |
1 ms |
812 KB |
Output is correct |
17 |
Correct |
1 ms |
848 KB |
Output is correct |
18 |
Correct |
1 ms |
848 KB |
Output is correct |
19 |
Correct |
1 ms |
848 KB |
Output is correct |
20 |
Correct |
1 ms |
848 KB |
Output is correct |
21 |
Correct |
1 ms |
848 KB |
Output is correct |
22 |
Correct |
1 ms |
848 KB |
Output is correct |
23 |
Correct |
1 ms |
976 KB |
Output is correct |
24 |
Correct |
1 ms |
976 KB |
Output is correct |
25 |
Correct |
1 ms |
464 KB |
Output is correct |
26 |
Correct |
1 ms |
848 KB |
Output is correct |
27 |
Correct |
1 ms |
848 KB |
Output is correct |
28 |
Correct |
1 ms |
848 KB |
Output is correct |
29 |
Correct |
1 ms |
848 KB |
Output is correct |
30 |
Correct |
1 ms |
848 KB |
Output is correct |
31 |
Correct |
1 ms |
748 KB |
Output is correct |
32 |
Correct |
1 ms |
976 KB |
Output is correct |
33 |
Correct |
1 ms |
976 KB |
Output is correct |
34 |
Correct |
1 ms |
976 KB |
Output is correct |
35 |
Correct |
1 ms |
976 KB |
Output is correct |
36 |
Correct |
22 ms |
14764 KB |
Output is correct |
37 |
Correct |
32 ms |
22592 KB |
Output is correct |
38 |
Correct |
29 ms |
22588 KB |
Output is correct |
39 |
Correct |
35 ms |
22480 KB |
Output is correct |
40 |
Correct |
29 ms |
22568 KB |
Output is correct |
41 |
Correct |
32 ms |
22600 KB |
Output is correct |
42 |
Correct |
29 ms |
22500 KB |
Output is correct |
43 |
Correct |
42 ms |
26176 KB |
Output is correct |
44 |
Correct |
30 ms |
23200 KB |
Output is correct |
45 |
Correct |
37 ms |
22600 KB |
Output is correct |
46 |
Correct |
36 ms |
22568 KB |
Output is correct |
47 |
Correct |
39 ms |
22588 KB |
Output is correct |
48 |
Correct |
34 ms |
22592 KB |
Output is correct |
49 |
Correct |
29 ms |
22560 KB |
Output is correct |
50 |
Correct |
35 ms |
23852 KB |
Output is correct |
51 |
Correct |
35 ms |
25136 KB |
Output is correct |
52 |
Correct |
34 ms |
22532 KB |
Output is correct |
53 |
Correct |
33 ms |
22588 KB |
Output is correct |
54 |
Correct |
41 ms |
22536 KB |
Output is correct |
55 |
Correct |
46 ms |
30016 KB |
Output is correct |
56 |
Correct |
50 ms |
29236 KB |
Output is correct |
57 |
Correct |
38 ms |
21820 KB |
Output is correct |
58 |
Correct |
38 ms |
22580 KB |
Output is correct |
59 |
Correct |
37 ms |
22576 KB |
Output is correct |
60 |
Correct |
34 ms |
22588 KB |
Output is correct |
61 |
Correct |
36 ms |
22500 KB |
Output is correct |
62 |
Correct |
35 ms |
22584 KB |
Output is correct |
63 |
Correct |
34 ms |
22568 KB |
Output is correct |
64 |
Correct |
52 ms |
29912 KB |
Output is correct |
65 |
Correct |
53 ms |
29980 KB |
Output is correct |
66 |
Correct |
42 ms |
26900 KB |
Output is correct |
67 |
Correct |
50 ms |
29544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4040 ms |
22508 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4069 ms |
5656 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
464 KB |
Output is correct |
2 |
Correct |
1 ms |
848 KB |
Output is correct |
3 |
Correct |
1 ms |
848 KB |
Output is correct |
4 |
Correct |
1 ms |
848 KB |
Output is correct |
5 |
Correct |
1 ms |
848 KB |
Output is correct |
6 |
Correct |
1 ms |
848 KB |
Output is correct |
7 |
Correct |
1 ms |
848 KB |
Output is correct |
8 |
Correct |
1 ms |
848 KB |
Output is correct |
9 |
Correct |
1 ms |
848 KB |
Output is correct |
10 |
Correct |
1 ms |
848 KB |
Output is correct |
11 |
Correct |
1 ms |
848 KB |
Output is correct |
12 |
Correct |
0 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
848 KB |
Output is correct |
14 |
Correct |
1 ms |
848 KB |
Output is correct |
15 |
Correct |
1 ms |
848 KB |
Output is correct |
16 |
Correct |
1 ms |
812 KB |
Output is correct |
17 |
Correct |
1 ms |
848 KB |
Output is correct |
18 |
Correct |
1 ms |
848 KB |
Output is correct |
19 |
Correct |
1 ms |
848 KB |
Output is correct |
20 |
Correct |
1 ms |
848 KB |
Output is correct |
21 |
Correct |
1 ms |
848 KB |
Output is correct |
22 |
Correct |
1 ms |
848 KB |
Output is correct |
23 |
Correct |
1 ms |
976 KB |
Output is correct |
24 |
Correct |
1 ms |
976 KB |
Output is correct |
25 |
Correct |
1 ms |
464 KB |
Output is correct |
26 |
Correct |
1 ms |
848 KB |
Output is correct |
27 |
Correct |
1 ms |
848 KB |
Output is correct |
28 |
Correct |
1 ms |
848 KB |
Output is correct |
29 |
Correct |
1 ms |
848 KB |
Output is correct |
30 |
Correct |
1 ms |
848 KB |
Output is correct |
31 |
Correct |
1 ms |
748 KB |
Output is correct |
32 |
Correct |
1 ms |
976 KB |
Output is correct |
33 |
Correct |
1 ms |
976 KB |
Output is correct |
34 |
Correct |
1 ms |
976 KB |
Output is correct |
35 |
Correct |
1 ms |
976 KB |
Output is correct |
36 |
Correct |
22 ms |
14764 KB |
Output is correct |
37 |
Correct |
32 ms |
22592 KB |
Output is correct |
38 |
Correct |
29 ms |
22588 KB |
Output is correct |
39 |
Correct |
35 ms |
22480 KB |
Output is correct |
40 |
Correct |
29 ms |
22568 KB |
Output is correct |
41 |
Correct |
32 ms |
22600 KB |
Output is correct |
42 |
Correct |
29 ms |
22500 KB |
Output is correct |
43 |
Correct |
42 ms |
26176 KB |
Output is correct |
44 |
Correct |
30 ms |
23200 KB |
Output is correct |
45 |
Correct |
37 ms |
22600 KB |
Output is correct |
46 |
Correct |
36 ms |
22568 KB |
Output is correct |
47 |
Correct |
39 ms |
22588 KB |
Output is correct |
48 |
Correct |
34 ms |
22592 KB |
Output is correct |
49 |
Correct |
29 ms |
22560 KB |
Output is correct |
50 |
Correct |
35 ms |
23852 KB |
Output is correct |
51 |
Correct |
35 ms |
25136 KB |
Output is correct |
52 |
Correct |
34 ms |
22532 KB |
Output is correct |
53 |
Correct |
33 ms |
22588 KB |
Output is correct |
54 |
Correct |
41 ms |
22536 KB |
Output is correct |
55 |
Correct |
46 ms |
30016 KB |
Output is correct |
56 |
Correct |
50 ms |
29236 KB |
Output is correct |
57 |
Correct |
38 ms |
21820 KB |
Output is correct |
58 |
Correct |
38 ms |
22580 KB |
Output is correct |
59 |
Correct |
37 ms |
22576 KB |
Output is correct |
60 |
Correct |
34 ms |
22588 KB |
Output is correct |
61 |
Correct |
36 ms |
22500 KB |
Output is correct |
62 |
Correct |
35 ms |
22584 KB |
Output is correct |
63 |
Correct |
34 ms |
22568 KB |
Output is correct |
64 |
Correct |
52 ms |
29912 KB |
Output is correct |
65 |
Correct |
53 ms |
29980 KB |
Output is correct |
66 |
Correct |
42 ms |
26900 KB |
Output is correct |
67 |
Correct |
50 ms |
29544 KB |
Output is correct |
68 |
Execution timed out |
4040 ms |
22508 KB |
Time limit exceeded |
69 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4053 ms |
17264 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |