#include <vector>
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
int const MAXN=1e5+10,LG=18;
int sp[MAXN][LG]={};
int n;
int dp[MAXN]={};
int a[MAXN]={};
bool uni=1;
int k=0;
void init(int N,vector<int> H)
{
for (int i=0;i<N;i++)
sp[i][0]=H[i],a[i]=H[i];
for (int i=1;(1<<i)<=N;i++)
for (int j=0;j+(1<<i)-1<N;j++)
sp[j][i]=max(sp[j][i-1],sp[j+(1<<(i-1))][i-1]);
n=N;
for (int i=0;i+1<n;i++)
{
if (a[i]<a[i+1])
k=i+1;
else
break;
}
for (int i=k;i+1<n;i++)
{
if (a[i]>a[i+1])
continue;
else
{
uni=0;
break;
}
}
}
int get(int l,int r)
{
if (l>r)
return -1;
int lg=log2(r-l+1);
return max(sp[l][lg],sp[r-(1<<lg)+1][lg]);
}
int max_towers(int L, int R, int D)
{
if (uni)
{
if (k>L&&k<R&&max(a[L],a[R])+D<=a[k])
return 2;
return 1;
}
int i=L,j=R;
if (R-L+1<3)
{
return R-L+1;
}
int ans=0;
for (int i=L;i<=R;i++)
{
dp[i]=1;
for (int j=i-2;j>=L;j--)
{
int z=get(j+1,i-1);
if (z>=max(a[i],a[j])+D)
dp[i]=max(dp[i],dp[j]+1);
}
ans=max(ans,dp[i]);
}
return ans;
}
Compilation message
towers.cpp: In function 'int max_towers(int, int, int)':
towers.cpp:54:6: warning: unused variable 'i' [-Wunused-variable]
54 | int i=L,j=R;
| ^
towers.cpp:54:10: warning: unused variable 'j' [-Wunused-variable]
54 | int i=L,j=R;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
352 ms |
5208 KB |
Output is correct |
2 |
Correct |
608 ms |
8536 KB |
Output is correct |
3 |
Correct |
665 ms |
8536 KB |
Output is correct |
4 |
Correct |
664 ms |
8528 KB |
Output is correct |
5 |
Correct |
656 ms |
8532 KB |
Output is correct |
6 |
Correct |
611 ms |
8536 KB |
Output is correct |
7 |
Correct |
619 ms |
8536 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
0 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
8 ms |
600 KB |
Output is correct |
3 |
Correct |
6 ms |
600 KB |
Output is correct |
4 |
Correct |
5 ms |
600 KB |
Output is correct |
5 |
Correct |
6 ms |
616 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
4 ms |
600 KB |
Output is correct |
8 |
Correct |
0 ms |
600 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
600 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
1 ms |
600 KB |
Output is correct |
16 |
Correct |
14 ms |
600 KB |
Output is correct |
17 |
Correct |
2 ms |
600 KB |
Output is correct |
18 |
Correct |
0 ms |
600 KB |
Output is correct |
19 |
Correct |
2 ms |
852 KB |
Output is correct |
20 |
Correct |
30 ms |
616 KB |
Output is correct |
21 |
Correct |
25 ms |
600 KB |
Output is correct |
22 |
Correct |
25 ms |
596 KB |
Output is correct |
23 |
Correct |
1 ms |
600 KB |
Output is correct |
24 |
Correct |
24 ms |
616 KB |
Output is correct |
25 |
Correct |
5 ms |
340 KB |
Output is correct |
26 |
Correct |
23 ms |
600 KB |
Output is correct |
27 |
Correct |
24 ms |
624 KB |
Output is correct |
28 |
Correct |
24 ms |
600 KB |
Output is correct |
29 |
Correct |
24 ms |
600 KB |
Output is correct |
30 |
Correct |
24 ms |
600 KB |
Output is correct |
31 |
Correct |
24 ms |
600 KB |
Output is correct |
32 |
Correct |
0 ms |
600 KB |
Output is correct |
33 |
Correct |
0 ms |
600 KB |
Output is correct |
34 |
Correct |
23 ms |
600 KB |
Output is correct |
35 |
Correct |
24 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
8 ms |
600 KB |
Output is correct |
3 |
Correct |
6 ms |
600 KB |
Output is correct |
4 |
Correct |
5 ms |
600 KB |
Output is correct |
5 |
Correct |
6 ms |
616 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
4 ms |
600 KB |
Output is correct |
8 |
Correct |
0 ms |
600 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
600 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
1 ms |
600 KB |
Output is correct |
16 |
Correct |
14 ms |
600 KB |
Output is correct |
17 |
Correct |
2 ms |
600 KB |
Output is correct |
18 |
Correct |
0 ms |
600 KB |
Output is correct |
19 |
Correct |
2 ms |
852 KB |
Output is correct |
20 |
Correct |
30 ms |
616 KB |
Output is correct |
21 |
Correct |
25 ms |
600 KB |
Output is correct |
22 |
Correct |
25 ms |
596 KB |
Output is correct |
23 |
Correct |
1 ms |
600 KB |
Output is correct |
24 |
Correct |
24 ms |
616 KB |
Output is correct |
25 |
Correct |
5 ms |
340 KB |
Output is correct |
26 |
Correct |
23 ms |
600 KB |
Output is correct |
27 |
Correct |
24 ms |
624 KB |
Output is correct |
28 |
Correct |
24 ms |
600 KB |
Output is correct |
29 |
Correct |
24 ms |
600 KB |
Output is correct |
30 |
Correct |
24 ms |
600 KB |
Output is correct |
31 |
Correct |
24 ms |
600 KB |
Output is correct |
32 |
Correct |
0 ms |
600 KB |
Output is correct |
33 |
Correct |
0 ms |
600 KB |
Output is correct |
34 |
Correct |
23 ms |
600 KB |
Output is correct |
35 |
Correct |
24 ms |
600 KB |
Output is correct |
36 |
Correct |
2299 ms |
5720 KB |
Output is correct |
37 |
Execution timed out |
4030 ms |
8668 KB |
Time limit exceeded |
38 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4064 ms |
8536 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4051 ms |
2420 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
8 ms |
600 KB |
Output is correct |
3 |
Correct |
6 ms |
600 KB |
Output is correct |
4 |
Correct |
5 ms |
600 KB |
Output is correct |
5 |
Correct |
6 ms |
616 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
4 ms |
600 KB |
Output is correct |
8 |
Correct |
0 ms |
600 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
600 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
1 ms |
600 KB |
Output is correct |
16 |
Correct |
14 ms |
600 KB |
Output is correct |
17 |
Correct |
2 ms |
600 KB |
Output is correct |
18 |
Correct |
0 ms |
600 KB |
Output is correct |
19 |
Correct |
2 ms |
852 KB |
Output is correct |
20 |
Correct |
30 ms |
616 KB |
Output is correct |
21 |
Correct |
25 ms |
600 KB |
Output is correct |
22 |
Correct |
25 ms |
596 KB |
Output is correct |
23 |
Correct |
1 ms |
600 KB |
Output is correct |
24 |
Correct |
24 ms |
616 KB |
Output is correct |
25 |
Correct |
5 ms |
340 KB |
Output is correct |
26 |
Correct |
23 ms |
600 KB |
Output is correct |
27 |
Correct |
24 ms |
624 KB |
Output is correct |
28 |
Correct |
24 ms |
600 KB |
Output is correct |
29 |
Correct |
24 ms |
600 KB |
Output is correct |
30 |
Correct |
24 ms |
600 KB |
Output is correct |
31 |
Correct |
24 ms |
600 KB |
Output is correct |
32 |
Correct |
0 ms |
600 KB |
Output is correct |
33 |
Correct |
0 ms |
600 KB |
Output is correct |
34 |
Correct |
23 ms |
600 KB |
Output is correct |
35 |
Correct |
24 ms |
600 KB |
Output is correct |
36 |
Correct |
2299 ms |
5720 KB |
Output is correct |
37 |
Execution timed out |
4030 ms |
8668 KB |
Time limit exceeded |
38 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
352 ms |
5208 KB |
Output is correct |
2 |
Correct |
608 ms |
8536 KB |
Output is correct |
3 |
Correct |
665 ms |
8536 KB |
Output is correct |
4 |
Correct |
664 ms |
8528 KB |
Output is correct |
5 |
Correct |
656 ms |
8532 KB |
Output is correct |
6 |
Correct |
611 ms |
8536 KB |
Output is correct |
7 |
Correct |
619 ms |
8536 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
0 ms |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
8 ms |
600 KB |
Output is correct |
13 |
Correct |
6 ms |
600 KB |
Output is correct |
14 |
Correct |
5 ms |
600 KB |
Output is correct |
15 |
Correct |
6 ms |
616 KB |
Output is correct |
16 |
Correct |
1 ms |
600 KB |
Output is correct |
17 |
Correct |
4 ms |
600 KB |
Output is correct |
18 |
Correct |
0 ms |
600 KB |
Output is correct |
19 |
Correct |
1 ms |
600 KB |
Output is correct |
20 |
Correct |
1 ms |
600 KB |
Output is correct |
21 |
Correct |
1 ms |
600 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
0 ms |
600 KB |
Output is correct |
24 |
Correct |
1 ms |
600 KB |
Output is correct |
25 |
Correct |
1 ms |
600 KB |
Output is correct |
26 |
Correct |
14 ms |
600 KB |
Output is correct |
27 |
Correct |
2 ms |
600 KB |
Output is correct |
28 |
Correct |
0 ms |
600 KB |
Output is correct |
29 |
Correct |
2 ms |
852 KB |
Output is correct |
30 |
Correct |
30 ms |
616 KB |
Output is correct |
31 |
Correct |
25 ms |
600 KB |
Output is correct |
32 |
Correct |
25 ms |
596 KB |
Output is correct |
33 |
Correct |
1 ms |
600 KB |
Output is correct |
34 |
Correct |
24 ms |
616 KB |
Output is correct |
35 |
Correct |
5 ms |
340 KB |
Output is correct |
36 |
Correct |
23 ms |
600 KB |
Output is correct |
37 |
Correct |
24 ms |
624 KB |
Output is correct |
38 |
Correct |
24 ms |
600 KB |
Output is correct |
39 |
Correct |
24 ms |
600 KB |
Output is correct |
40 |
Correct |
24 ms |
600 KB |
Output is correct |
41 |
Correct |
24 ms |
600 KB |
Output is correct |
42 |
Correct |
0 ms |
600 KB |
Output is correct |
43 |
Correct |
0 ms |
600 KB |
Output is correct |
44 |
Correct |
23 ms |
600 KB |
Output is correct |
45 |
Correct |
24 ms |
600 KB |
Output is correct |
46 |
Correct |
2299 ms |
5720 KB |
Output is correct |
47 |
Execution timed out |
4030 ms |
8668 KB |
Time limit exceeded |
48 |
Halted |
0 ms |
0 KB |
- |