#include "towers.h"
#include <bits/stdc++.h>
//#include <cassert>
//#include <cstdio>
#define ll int
//#include <vector>
using namespace std;
vector<ll>v;
const ll N=1e5+9;
const ll INF=1e9;
ll tr[4*N],sz,szz,k,fll;
void init(int N, std::vector<int> H) {
for(auto to:H){
v.push_back(to);
}
k=0,fll=0;
for(int i=1; i<N; i++){
if(v[i]>v[i-1]) szz=i;
else fll=1;
if(fll==1 && v[i-1]<=v[i]) k=1;
}
}
int max_towers(int L, int R, int D) {
ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
if(k==0){
if(L<=szz && szz<=R && v[L]<=v[szz]-D && v[R]<=v[szz]-D) return 2;
return 1;
}
ll curr=-1;
ll mn=v[L],res=1;
for(int i=L+1; i<=R; i++){
if(curr<0){
if(v[i]<mn) mn=v[i];
else if(v[i]-D>=mn) curr=v[i];
}
else{
if(v[i]<=curr-D) res++,mn=v[i],curr=-curr;
else if(v[i]>curr) curr=v[i];
}
}
return res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
340 ms |
1096 KB |
Output is correct |
2 |
Correct |
769 ms |
1732 KB |
Output is correct |
3 |
Correct |
702 ms |
1700 KB |
Output is correct |
4 |
Correct |
702 ms |
1700 KB |
Output is correct |
5 |
Correct |
654 ms |
1692 KB |
Output is correct |
6 |
Correct |
806 ms |
1740 KB |
Output is correct |
7 |
Correct |
890 ms |
1716 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
304 KB |
Output is correct |
10 |
Correct |
0 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
0 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 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 |
0 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 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 |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 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 |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
336 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 |
0 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
0 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 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 |
0 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 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 |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 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 |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
336 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 |
8 ms |
1104 KB |
Output is correct |
37 |
Correct |
13 ms |
1740 KB |
Output is correct |
38 |
Correct |
13 ms |
1728 KB |
Output is correct |
39 |
Correct |
15 ms |
1708 KB |
Output is correct |
40 |
Correct |
15 ms |
1680 KB |
Output is correct |
41 |
Correct |
14 ms |
1700 KB |
Output is correct |
42 |
Correct |
14 ms |
1604 KB |
Output is correct |
43 |
Correct |
12 ms |
1740 KB |
Output is correct |
44 |
Correct |
13 ms |
1696 KB |
Output is correct |
45 |
Correct |
18 ms |
1696 KB |
Output is correct |
46 |
Correct |
13 ms |
1692 KB |
Output is correct |
47 |
Correct |
13 ms |
1724 KB |
Output is correct |
48 |
Correct |
12 ms |
1740 KB |
Output is correct |
49 |
Correct |
21 ms |
1712 KB |
Output is correct |
50 |
Correct |
18 ms |
1700 KB |
Output is correct |
51 |
Correct |
15 ms |
1604 KB |
Output is correct |
52 |
Correct |
14 ms |
1740 KB |
Output is correct |
53 |
Correct |
13 ms |
1692 KB |
Output is correct |
54 |
Correct |
14 ms |
1704 KB |
Output is correct |
55 |
Correct |
13 ms |
1704 KB |
Output is correct |
56 |
Correct |
20 ms |
1608 KB |
Output is correct |
57 |
Correct |
14 ms |
1692 KB |
Output is correct |
58 |
Correct |
14 ms |
1740 KB |
Output is correct |
59 |
Correct |
16 ms |
1716 KB |
Output is correct |
60 |
Correct |
15 ms |
1716 KB |
Output is correct |
61 |
Correct |
16 ms |
1732 KB |
Output is correct |
62 |
Correct |
14 ms |
1696 KB |
Output is correct |
63 |
Correct |
14 ms |
1700 KB |
Output is correct |
64 |
Correct |
15 ms |
1720 KB |
Output is correct |
65 |
Correct |
20 ms |
1740 KB |
Output is correct |
66 |
Correct |
16 ms |
1696 KB |
Output is correct |
67 |
Correct |
12 ms |
1732 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4005 ms |
1708 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3243 ms |
720 KB |
Output is correct |
2 |
Execution timed out |
4048 ms |
1700 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
0 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 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 |
0 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 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 |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 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 |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
336 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 |
8 ms |
1104 KB |
Output is correct |
37 |
Correct |
13 ms |
1740 KB |
Output is correct |
38 |
Correct |
13 ms |
1728 KB |
Output is correct |
39 |
Correct |
15 ms |
1708 KB |
Output is correct |
40 |
Correct |
15 ms |
1680 KB |
Output is correct |
41 |
Correct |
14 ms |
1700 KB |
Output is correct |
42 |
Correct |
14 ms |
1604 KB |
Output is correct |
43 |
Correct |
12 ms |
1740 KB |
Output is correct |
44 |
Correct |
13 ms |
1696 KB |
Output is correct |
45 |
Correct |
18 ms |
1696 KB |
Output is correct |
46 |
Correct |
13 ms |
1692 KB |
Output is correct |
47 |
Correct |
13 ms |
1724 KB |
Output is correct |
48 |
Correct |
12 ms |
1740 KB |
Output is correct |
49 |
Correct |
21 ms |
1712 KB |
Output is correct |
50 |
Correct |
18 ms |
1700 KB |
Output is correct |
51 |
Correct |
15 ms |
1604 KB |
Output is correct |
52 |
Correct |
14 ms |
1740 KB |
Output is correct |
53 |
Correct |
13 ms |
1692 KB |
Output is correct |
54 |
Correct |
14 ms |
1704 KB |
Output is correct |
55 |
Correct |
13 ms |
1704 KB |
Output is correct |
56 |
Correct |
20 ms |
1608 KB |
Output is correct |
57 |
Correct |
14 ms |
1692 KB |
Output is correct |
58 |
Correct |
14 ms |
1740 KB |
Output is correct |
59 |
Correct |
16 ms |
1716 KB |
Output is correct |
60 |
Correct |
15 ms |
1716 KB |
Output is correct |
61 |
Correct |
16 ms |
1732 KB |
Output is correct |
62 |
Correct |
14 ms |
1696 KB |
Output is correct |
63 |
Correct |
14 ms |
1700 KB |
Output is correct |
64 |
Correct |
15 ms |
1720 KB |
Output is correct |
65 |
Correct |
20 ms |
1740 KB |
Output is correct |
66 |
Correct |
16 ms |
1696 KB |
Output is correct |
67 |
Correct |
12 ms |
1732 KB |
Output is correct |
68 |
Execution timed out |
4005 ms |
1708 KB |
Time limit exceeded |
69 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
340 ms |
1096 KB |
Output is correct |
2 |
Correct |
769 ms |
1732 KB |
Output is correct |
3 |
Correct |
702 ms |
1700 KB |
Output is correct |
4 |
Correct |
702 ms |
1700 KB |
Output is correct |
5 |
Correct |
654 ms |
1692 KB |
Output is correct |
6 |
Correct |
806 ms |
1740 KB |
Output is correct |
7 |
Correct |
890 ms |
1716 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
304 KB |
Output is correct |
10 |
Correct |
0 ms |
336 KB |
Output is correct |
11 |
Correct |
0 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
0 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 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 |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
0 ms |
208 KB |
Output is correct |
23 |
Correct |
0 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
336 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 |
1 ms |
336 KB |
Output is correct |
37 |
Correct |
1 ms |
336 KB |
Output is correct |
38 |
Correct |
1 ms |
336 KB |
Output is correct |
39 |
Correct |
1 ms |
336 KB |
Output is correct |
40 |
Correct |
1 ms |
336 KB |
Output is correct |
41 |
Correct |
1 ms |
336 KB |
Output is correct |
42 |
Correct |
1 ms |
336 KB |
Output is correct |
43 |
Correct |
1 ms |
336 KB |
Output is correct |
44 |
Correct |
1 ms |
336 KB |
Output is correct |
45 |
Correct |
1 ms |
336 KB |
Output is correct |
46 |
Correct |
8 ms |
1104 KB |
Output is correct |
47 |
Correct |
13 ms |
1740 KB |
Output is correct |
48 |
Correct |
13 ms |
1728 KB |
Output is correct |
49 |
Correct |
15 ms |
1708 KB |
Output is correct |
50 |
Correct |
15 ms |
1680 KB |
Output is correct |
51 |
Correct |
14 ms |
1700 KB |
Output is correct |
52 |
Correct |
14 ms |
1604 KB |
Output is correct |
53 |
Correct |
12 ms |
1740 KB |
Output is correct |
54 |
Correct |
13 ms |
1696 KB |
Output is correct |
55 |
Correct |
18 ms |
1696 KB |
Output is correct |
56 |
Correct |
13 ms |
1692 KB |
Output is correct |
57 |
Correct |
13 ms |
1724 KB |
Output is correct |
58 |
Correct |
12 ms |
1740 KB |
Output is correct |
59 |
Correct |
21 ms |
1712 KB |
Output is correct |
60 |
Correct |
18 ms |
1700 KB |
Output is correct |
61 |
Correct |
15 ms |
1604 KB |
Output is correct |
62 |
Correct |
14 ms |
1740 KB |
Output is correct |
63 |
Correct |
13 ms |
1692 KB |
Output is correct |
64 |
Correct |
14 ms |
1704 KB |
Output is correct |
65 |
Correct |
13 ms |
1704 KB |
Output is correct |
66 |
Correct |
20 ms |
1608 KB |
Output is correct |
67 |
Correct |
14 ms |
1692 KB |
Output is correct |
68 |
Correct |
14 ms |
1740 KB |
Output is correct |
69 |
Correct |
16 ms |
1716 KB |
Output is correct |
70 |
Correct |
15 ms |
1716 KB |
Output is correct |
71 |
Correct |
16 ms |
1732 KB |
Output is correct |
72 |
Correct |
14 ms |
1696 KB |
Output is correct |
73 |
Correct |
14 ms |
1700 KB |
Output is correct |
74 |
Correct |
15 ms |
1720 KB |
Output is correct |
75 |
Correct |
20 ms |
1740 KB |
Output is correct |
76 |
Correct |
16 ms |
1696 KB |
Output is correct |
77 |
Correct |
12 ms |
1732 KB |
Output is correct |
78 |
Execution timed out |
4005 ms |
1708 KB |
Time limit exceeded |
79 |
Halted |
0 ms |
0 KB |
- |