#include "mountains.h"
#include <vector>
#include<bits/stdc++.h>
using namespace std;
long long a[2005];
int dp[2005][2005];
int visit[2005][2005];
int n;
int dy[2005];
int f(int l,int r){
if(l>r)return 0;
if(l==r)return 1;
if(r==l+1)return 1;
if(visit[l][r])return dp[l][r];
visit[l][r]=1;
int i,j;
dp[l][r]=f(l,r-1);
i=r;
int k=i-1;
int x=1;
for(int j=i-2 ; j>=l ; j--){
if((a[i]-a[k])*(i-j)>=(a[i]-a[j])*(i-k)){
x+=f(j+1,k-1);
k=j;
}
}
x+=f(l,k-1);
dp[l][r]=max(dp[l][r],x);
return dp[l][r];
}
int maximum_deevs(std::vector<int> y) {
n=y.size();
for(int i=1 ; i<=n ; i++)
{
a[i]=y[i-1];
}
return f(1,n);
}
Compilation message
mountains.cpp: In function 'int f(int, int)':
mountains.cpp:18:11: warning: unused variable 'j' [-Wunused-variable]
18 | int i,j;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
0 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
0 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
0 ms |
364 KB |
Output is correct |
13 |
Correct |
0 ms |
364 KB |
Output is correct |
14 |
Correct |
0 ms |
364 KB |
Output is correct |
15 |
Correct |
0 ms |
364 KB |
Output is correct |
16 |
Correct |
0 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
0 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
0 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
0 ms |
364 KB |
Output is correct |
13 |
Correct |
0 ms |
364 KB |
Output is correct |
14 |
Correct |
0 ms |
364 KB |
Output is correct |
15 |
Correct |
0 ms |
364 KB |
Output is correct |
16 |
Correct |
0 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
396 KB |
Output is correct |
21 |
Correct |
0 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
0 ms |
364 KB |
Output is correct |
24 |
Correct |
0 ms |
364 KB |
Output is correct |
25 |
Correct |
0 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
0 ms |
364 KB |
Output is correct |
28 |
Correct |
0 ms |
364 KB |
Output is correct |
29 |
Correct |
1 ms |
512 KB |
Output is correct |
30 |
Correct |
0 ms |
492 KB |
Output is correct |
31 |
Correct |
1 ms |
492 KB |
Output is correct |
32 |
Correct |
1 ms |
492 KB |
Output is correct |
33 |
Correct |
0 ms |
364 KB |
Output is correct |
34 |
Correct |
1 ms |
364 KB |
Output is correct |
35 |
Correct |
1 ms |
364 KB |
Output is correct |
36 |
Correct |
1 ms |
364 KB |
Output is correct |
37 |
Correct |
1 ms |
364 KB |
Output is correct |
38 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
0 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
0 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
0 ms |
364 KB |
Output is correct |
13 |
Correct |
0 ms |
364 KB |
Output is correct |
14 |
Correct |
0 ms |
364 KB |
Output is correct |
15 |
Correct |
0 ms |
364 KB |
Output is correct |
16 |
Correct |
0 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
396 KB |
Output is correct |
21 |
Correct |
0 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
0 ms |
364 KB |
Output is correct |
24 |
Correct |
0 ms |
364 KB |
Output is correct |
25 |
Correct |
0 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
0 ms |
364 KB |
Output is correct |
28 |
Correct |
0 ms |
364 KB |
Output is correct |
29 |
Correct |
1 ms |
512 KB |
Output is correct |
30 |
Correct |
0 ms |
492 KB |
Output is correct |
31 |
Correct |
1 ms |
492 KB |
Output is correct |
32 |
Correct |
1 ms |
492 KB |
Output is correct |
33 |
Correct |
0 ms |
364 KB |
Output is correct |
34 |
Correct |
1 ms |
364 KB |
Output is correct |
35 |
Correct |
1 ms |
364 KB |
Output is correct |
36 |
Correct |
1 ms |
364 KB |
Output is correct |
37 |
Correct |
1 ms |
364 KB |
Output is correct |
38 |
Correct |
1 ms |
364 KB |
Output is correct |
39 |
Correct |
1 ms |
620 KB |
Output is correct |
40 |
Correct |
1 ms |
748 KB |
Output is correct |
41 |
Correct |
1 ms |
620 KB |
Output is correct |
42 |
Correct |
1 ms |
748 KB |
Output is correct |
43 |
Correct |
1 ms |
616 KB |
Output is correct |
44 |
Correct |
1 ms |
748 KB |
Output is correct |
45 |
Correct |
1 ms |
748 KB |
Output is correct |
46 |
Correct |
1 ms |
748 KB |
Output is correct |
47 |
Correct |
1 ms |
748 KB |
Output is correct |
48 |
Correct |
1 ms |
748 KB |
Output is correct |
49 |
Correct |
1 ms |
748 KB |
Output is correct |
50 |
Correct |
1 ms |
748 KB |
Output is correct |
51 |
Correct |
1 ms |
876 KB |
Output is correct |
52 |
Correct |
2 ms |
1644 KB |
Output is correct |
53 |
Correct |
3 ms |
1516 KB |
Output is correct |
54 |
Correct |
2 ms |
1772 KB |
Output is correct |
55 |
Correct |
2 ms |
1644 KB |
Output is correct |
56 |
Correct |
2 ms |
1644 KB |
Output is correct |
57 |
Correct |
1 ms |
364 KB |
Output is correct |
58 |
Correct |
1 ms |
896 KB |
Output is correct |
59 |
Correct |
1 ms |
748 KB |
Output is correct |
60 |
Correct |
1 ms |
364 KB |
Output is correct |
61 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
0 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
0 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
0 ms |
364 KB |
Output is correct |
13 |
Correct |
0 ms |
364 KB |
Output is correct |
14 |
Correct |
0 ms |
364 KB |
Output is correct |
15 |
Correct |
0 ms |
364 KB |
Output is correct |
16 |
Correct |
0 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
396 KB |
Output is correct |
21 |
Correct |
0 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
0 ms |
364 KB |
Output is correct |
24 |
Correct |
0 ms |
364 KB |
Output is correct |
25 |
Correct |
0 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
0 ms |
364 KB |
Output is correct |
28 |
Correct |
0 ms |
364 KB |
Output is correct |
29 |
Correct |
1 ms |
512 KB |
Output is correct |
30 |
Correct |
0 ms |
492 KB |
Output is correct |
31 |
Correct |
1 ms |
492 KB |
Output is correct |
32 |
Correct |
1 ms |
492 KB |
Output is correct |
33 |
Correct |
0 ms |
364 KB |
Output is correct |
34 |
Correct |
1 ms |
364 KB |
Output is correct |
35 |
Correct |
1 ms |
364 KB |
Output is correct |
36 |
Correct |
1 ms |
364 KB |
Output is correct |
37 |
Correct |
1 ms |
364 KB |
Output is correct |
38 |
Correct |
1 ms |
364 KB |
Output is correct |
39 |
Correct |
1 ms |
620 KB |
Output is correct |
40 |
Correct |
1 ms |
748 KB |
Output is correct |
41 |
Correct |
1 ms |
620 KB |
Output is correct |
42 |
Correct |
1 ms |
748 KB |
Output is correct |
43 |
Correct |
1 ms |
616 KB |
Output is correct |
44 |
Correct |
1 ms |
748 KB |
Output is correct |
45 |
Correct |
1 ms |
748 KB |
Output is correct |
46 |
Correct |
1 ms |
748 KB |
Output is correct |
47 |
Correct |
1 ms |
748 KB |
Output is correct |
48 |
Correct |
1 ms |
748 KB |
Output is correct |
49 |
Correct |
1 ms |
748 KB |
Output is correct |
50 |
Correct |
1 ms |
748 KB |
Output is correct |
51 |
Correct |
1 ms |
876 KB |
Output is correct |
52 |
Correct |
2 ms |
1644 KB |
Output is correct |
53 |
Correct |
3 ms |
1516 KB |
Output is correct |
54 |
Correct |
2 ms |
1772 KB |
Output is correct |
55 |
Correct |
2 ms |
1644 KB |
Output is correct |
56 |
Correct |
2 ms |
1644 KB |
Output is correct |
57 |
Correct |
1 ms |
364 KB |
Output is correct |
58 |
Correct |
1 ms |
896 KB |
Output is correct |
59 |
Correct |
1 ms |
748 KB |
Output is correct |
60 |
Correct |
1 ms |
364 KB |
Output is correct |
61 |
Correct |
1 ms |
364 KB |
Output is correct |
62 |
Correct |
3 ms |
1516 KB |
Output is correct |
63 |
Correct |
6 ms |
2668 KB |
Output is correct |
64 |
Correct |
6 ms |
2796 KB |
Output is correct |
65 |
Correct |
6 ms |
2668 KB |
Output is correct |
66 |
Correct |
6 ms |
2796 KB |
Output is correct |
67 |
Correct |
6 ms |
2796 KB |
Output is correct |
68 |
Correct |
6 ms |
2668 KB |
Output is correct |
69 |
Correct |
6 ms |
2668 KB |
Output is correct |
70 |
Correct |
8 ms |
2668 KB |
Output is correct |
71 |
Correct |
8 ms |
2156 KB |
Output is correct |
72 |
Correct |
8 ms |
2156 KB |
Output is correct |
73 |
Correct |
8 ms |
2540 KB |
Output is correct |
74 |
Correct |
8 ms |
2284 KB |
Output is correct |
75 |
Correct |
8 ms |
2796 KB |
Output is correct |
76 |
Correct |
7 ms |
3564 KB |
Output is correct |
77 |
Correct |
22 ms |
2412 KB |
Output is correct |
78 |
Correct |
19 ms |
2156 KB |
Output is correct |
79 |
Correct |
22 ms |
2284 KB |
Output is correct |
80 |
Correct |
21 ms |
2148 KB |
Output is correct |
81 |
Correct |
19 ms |
2284 KB |
Output is correct |
82 |
Correct |
4 ms |
492 KB |
Output is correct |
83 |
Correct |
15 ms |
4588 KB |
Output is correct |
84 |
Correct |
13 ms |
4716 KB |
Output is correct |
85 |
Correct |
8 ms |
620 KB |
Output is correct |
86 |
Correct |
8 ms |
620 KB |
Output is correct |