#include <bits/stdc++.h>
#include "towers.h"
using namespace std;
#define mp make_pair
#define fr first
#define sc second
const long long inf=1e18;
long long a[100069],ps[100069];
void init(int n,vector<int> aa)
{
long long i;
for(i=1;i<=n;i++)
{
a[i]=aa[i-1];
}
for(i=1;i<=n;i++)
{
ps[i]=ps[i-1]+(i>1&&i<n&&a[i]<a[i-1]&&a[i]<a[i+1]);
}
}
int max_towers(int lb,int rb,int cw)
{
lb++;
rb++;
if(lb==rb)
{
return 1;
}
else
{
long long i,j,mn,mx,z=ps[rb-1]-ps[lb]+(a[lb]<a[lb+1])+(a[rb]<a[rb-1]);
for(i=lb;i<=rb;i++)
{
if((i==lb&&a[i]<a[i+1])||(i==rb&&a[i]<a[i-1])||(i>lb&&i<rb&&a[i]<a[i-1]&&a[i]<a[i+1]))
{
mn=inf;
mx=-inf;
for(j=i-1;j>=lb;j--)
{
if(a[j]<a[i])
{
break;
}
mx=max(mx,a[j]);
}
if(j>=lb)
{
mn=min(mn,mx);
}
mx=-inf;
for(j=i+1;j<=rb;j++)
{
if(a[j]<a[i])
{
break;
}
mx=max(mx,a[j]);
}
if(j<=rb)
{
mn=min(mn,mx);
}
if(mn-a[i]<cw)
{
z--;
}
}
}
return z;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3557 ms |
1608 KB |
Output is correct |
2 |
Execution timed out |
4066 ms |
2640 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 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 |
1 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 |
300 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 |
308 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 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 |
1 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 |
300 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 |
308 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 |
9 ms |
1744 KB |
Output is correct |
37 |
Correct |
15 ms |
2604 KB |
Output is correct |
38 |
Correct |
14 ms |
2580 KB |
Output is correct |
39 |
Correct |
13 ms |
2508 KB |
Output is correct |
40 |
Correct |
13 ms |
2584 KB |
Output is correct |
41 |
Correct |
15 ms |
2596 KB |
Output is correct |
42 |
Correct |
13 ms |
2620 KB |
Output is correct |
43 |
Correct |
16 ms |
2632 KB |
Output is correct |
44 |
Correct |
13 ms |
2640 KB |
Output is correct |
45 |
Correct |
13 ms |
2628 KB |
Output is correct |
46 |
Correct |
21 ms |
2580 KB |
Output is correct |
47 |
Correct |
14 ms |
2612 KB |
Output is correct |
48 |
Correct |
14 ms |
2616 KB |
Output is correct |
49 |
Correct |
18 ms |
2632 KB |
Output is correct |
50 |
Correct |
17 ms |
2632 KB |
Output is correct |
51 |
Correct |
14 ms |
2596 KB |
Output is correct |
52 |
Correct |
16 ms |
2596 KB |
Output is correct |
53 |
Correct |
22 ms |
2592 KB |
Output is correct |
54 |
Correct |
15 ms |
2612 KB |
Output is correct |
55 |
Correct |
13 ms |
2592 KB |
Output is correct |
56 |
Correct |
21 ms |
2592 KB |
Output is correct |
57 |
Correct |
16 ms |
2480 KB |
Output is correct |
58 |
Correct |
25 ms |
2632 KB |
Output is correct |
59 |
Correct |
17 ms |
2604 KB |
Output is correct |
60 |
Correct |
15 ms |
2596 KB |
Output is correct |
61 |
Correct |
15 ms |
2604 KB |
Output is correct |
62 |
Correct |
15 ms |
2592 KB |
Output is correct |
63 |
Correct |
16 ms |
2604 KB |
Output is correct |
64 |
Correct |
13 ms |
2616 KB |
Output is correct |
65 |
Correct |
21 ms |
2596 KB |
Output is correct |
66 |
Correct |
15 ms |
2600 KB |
Output is correct |
67 |
Correct |
13 ms |
2632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4051 ms |
2620 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4038 ms |
848 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 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 |
1 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 |
300 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 |
308 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 |
9 ms |
1744 KB |
Output is correct |
37 |
Correct |
15 ms |
2604 KB |
Output is correct |
38 |
Correct |
14 ms |
2580 KB |
Output is correct |
39 |
Correct |
13 ms |
2508 KB |
Output is correct |
40 |
Correct |
13 ms |
2584 KB |
Output is correct |
41 |
Correct |
15 ms |
2596 KB |
Output is correct |
42 |
Correct |
13 ms |
2620 KB |
Output is correct |
43 |
Correct |
16 ms |
2632 KB |
Output is correct |
44 |
Correct |
13 ms |
2640 KB |
Output is correct |
45 |
Correct |
13 ms |
2628 KB |
Output is correct |
46 |
Correct |
21 ms |
2580 KB |
Output is correct |
47 |
Correct |
14 ms |
2612 KB |
Output is correct |
48 |
Correct |
14 ms |
2616 KB |
Output is correct |
49 |
Correct |
18 ms |
2632 KB |
Output is correct |
50 |
Correct |
17 ms |
2632 KB |
Output is correct |
51 |
Correct |
14 ms |
2596 KB |
Output is correct |
52 |
Correct |
16 ms |
2596 KB |
Output is correct |
53 |
Correct |
22 ms |
2592 KB |
Output is correct |
54 |
Correct |
15 ms |
2612 KB |
Output is correct |
55 |
Correct |
13 ms |
2592 KB |
Output is correct |
56 |
Correct |
21 ms |
2592 KB |
Output is correct |
57 |
Correct |
16 ms |
2480 KB |
Output is correct |
58 |
Correct |
25 ms |
2632 KB |
Output is correct |
59 |
Correct |
17 ms |
2604 KB |
Output is correct |
60 |
Correct |
15 ms |
2596 KB |
Output is correct |
61 |
Correct |
15 ms |
2604 KB |
Output is correct |
62 |
Correct |
15 ms |
2592 KB |
Output is correct |
63 |
Correct |
16 ms |
2604 KB |
Output is correct |
64 |
Correct |
13 ms |
2616 KB |
Output is correct |
65 |
Correct |
21 ms |
2596 KB |
Output is correct |
66 |
Correct |
15 ms |
2600 KB |
Output is correct |
67 |
Correct |
13 ms |
2632 KB |
Output is correct |
68 |
Execution timed out |
4051 ms |
2620 KB |
Time limit exceeded |
69 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3557 ms |
1608 KB |
Output is correct |
2 |
Execution timed out |
4066 ms |
2640 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |