#include "mountains.h"
#include <bits/stdc++.h>
#define int long long
using namespace std;
struct point{
int x,y;
}p[2001];
inline point operator-(point a, point b){
return {a.x-b.x,a.y-b.y};
}
inline int operator*(point a, point b){
return a.x*b.y-a.y*b.x;
}
int dp[2001][2001];
vector <int> v[2001];
int f(int i, int j){
if (i==j)
return 1;
if (i>j)
return 0;
if (dp[i][j]!=-1)
return dp[i][j];
int res=1;
for (int k=0;k<v[j].size()-1;k++)
res+=f(max(v[j][k]+1,i),v[j][k+1]-1);
return dp[i][j]=max(f(i,j-1),res);
}
int32_t maximum_deevs(vector <int32_t> y){
for (int i=1;i<=y.size();i++){
v[i].push_back(0);
p[i]={i,y[i-1]};
for (int j=1;j<i;j++){
while (v[i].size()>1&&(p[j]-p[i])*(p[v[i].back()]-p[i])>0)
v[i].pop_back();
v[i].push_back(j);
}
}
memset(dp,-1,sizeof(dp));
return f(1,y.size());
}
Compilation message
mountains.cpp: In function 'long long int f(long long int, long long int)':
mountains.cpp:24:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | for (int k=0;k<v[j].size()-1;k++)
| ~^~~~~~~~~~~~~~
mountains.cpp: In function 'int32_t maximum_deevs(std::vector<int>)':
mountains.cpp:29:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | for (int i=1;i<=y.size();i++){
| ~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
31572 KB |
Output is correct |
2 |
Correct |
13 ms |
31572 KB |
Output is correct |
3 |
Correct |
13 ms |
31572 KB |
Output is correct |
4 |
Correct |
13 ms |
31572 KB |
Output is correct |
5 |
Correct |
14 ms |
31620 KB |
Output is correct |
6 |
Correct |
14 ms |
31604 KB |
Output is correct |
7 |
Correct |
13 ms |
31636 KB |
Output is correct |
8 |
Correct |
17 ms |
31660 KB |
Output is correct |
9 |
Correct |
17 ms |
31700 KB |
Output is correct |
10 |
Correct |
14 ms |
31572 KB |
Output is correct |
11 |
Correct |
13 ms |
31608 KB |
Output is correct |
12 |
Correct |
13 ms |
31604 KB |
Output is correct |
13 |
Correct |
13 ms |
31700 KB |
Output is correct |
14 |
Correct |
14 ms |
31572 KB |
Output is correct |
15 |
Correct |
13 ms |
31700 KB |
Output is correct |
16 |
Correct |
14 ms |
31612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
31572 KB |
Output is correct |
2 |
Correct |
13 ms |
31572 KB |
Output is correct |
3 |
Correct |
13 ms |
31572 KB |
Output is correct |
4 |
Correct |
13 ms |
31572 KB |
Output is correct |
5 |
Correct |
14 ms |
31620 KB |
Output is correct |
6 |
Correct |
14 ms |
31604 KB |
Output is correct |
7 |
Correct |
13 ms |
31636 KB |
Output is correct |
8 |
Correct |
17 ms |
31660 KB |
Output is correct |
9 |
Correct |
17 ms |
31700 KB |
Output is correct |
10 |
Correct |
14 ms |
31572 KB |
Output is correct |
11 |
Correct |
13 ms |
31608 KB |
Output is correct |
12 |
Correct |
13 ms |
31604 KB |
Output is correct |
13 |
Correct |
13 ms |
31700 KB |
Output is correct |
14 |
Correct |
14 ms |
31572 KB |
Output is correct |
15 |
Correct |
13 ms |
31700 KB |
Output is correct |
16 |
Correct |
14 ms |
31612 KB |
Output is correct |
17 |
Correct |
17 ms |
31700 KB |
Output is correct |
18 |
Correct |
14 ms |
31700 KB |
Output is correct |
19 |
Correct |
13 ms |
31700 KB |
Output is correct |
20 |
Correct |
16 ms |
31700 KB |
Output is correct |
21 |
Correct |
13 ms |
31692 KB |
Output is correct |
22 |
Correct |
14 ms |
31660 KB |
Output is correct |
23 |
Correct |
14 ms |
31624 KB |
Output is correct |
24 |
Correct |
17 ms |
31700 KB |
Output is correct |
25 |
Correct |
14 ms |
31588 KB |
Output is correct |
26 |
Correct |
16 ms |
31584 KB |
Output is correct |
27 |
Correct |
14 ms |
31688 KB |
Output is correct |
28 |
Correct |
13 ms |
31700 KB |
Output is correct |
29 |
Correct |
15 ms |
31636 KB |
Output is correct |
30 |
Correct |
15 ms |
31600 KB |
Output is correct |
31 |
Correct |
14 ms |
31700 KB |
Output is correct |
32 |
Correct |
14 ms |
31620 KB |
Output is correct |
33 |
Correct |
14 ms |
31584 KB |
Output is correct |
34 |
Correct |
14 ms |
31700 KB |
Output is correct |
35 |
Correct |
13 ms |
31600 KB |
Output is correct |
36 |
Correct |
14 ms |
31700 KB |
Output is correct |
37 |
Correct |
14 ms |
31700 KB |
Output is correct |
38 |
Correct |
13 ms |
31588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
31572 KB |
Output is correct |
2 |
Correct |
13 ms |
31572 KB |
Output is correct |
3 |
Correct |
13 ms |
31572 KB |
Output is correct |
4 |
Correct |
13 ms |
31572 KB |
Output is correct |
5 |
Correct |
14 ms |
31620 KB |
Output is correct |
6 |
Correct |
14 ms |
31604 KB |
Output is correct |
7 |
Correct |
13 ms |
31636 KB |
Output is correct |
8 |
Correct |
17 ms |
31660 KB |
Output is correct |
9 |
Correct |
17 ms |
31700 KB |
Output is correct |
10 |
Correct |
14 ms |
31572 KB |
Output is correct |
11 |
Correct |
13 ms |
31608 KB |
Output is correct |
12 |
Correct |
13 ms |
31604 KB |
Output is correct |
13 |
Correct |
13 ms |
31700 KB |
Output is correct |
14 |
Correct |
14 ms |
31572 KB |
Output is correct |
15 |
Correct |
13 ms |
31700 KB |
Output is correct |
16 |
Correct |
14 ms |
31612 KB |
Output is correct |
17 |
Correct |
17 ms |
31700 KB |
Output is correct |
18 |
Correct |
14 ms |
31700 KB |
Output is correct |
19 |
Correct |
13 ms |
31700 KB |
Output is correct |
20 |
Correct |
16 ms |
31700 KB |
Output is correct |
21 |
Correct |
13 ms |
31692 KB |
Output is correct |
22 |
Correct |
14 ms |
31660 KB |
Output is correct |
23 |
Correct |
14 ms |
31624 KB |
Output is correct |
24 |
Correct |
17 ms |
31700 KB |
Output is correct |
25 |
Correct |
14 ms |
31588 KB |
Output is correct |
26 |
Correct |
16 ms |
31584 KB |
Output is correct |
27 |
Correct |
14 ms |
31688 KB |
Output is correct |
28 |
Correct |
13 ms |
31700 KB |
Output is correct |
29 |
Correct |
15 ms |
31636 KB |
Output is correct |
30 |
Correct |
15 ms |
31600 KB |
Output is correct |
31 |
Correct |
14 ms |
31700 KB |
Output is correct |
32 |
Correct |
14 ms |
31620 KB |
Output is correct |
33 |
Correct |
14 ms |
31584 KB |
Output is correct |
34 |
Correct |
14 ms |
31700 KB |
Output is correct |
35 |
Correct |
13 ms |
31600 KB |
Output is correct |
36 |
Correct |
14 ms |
31700 KB |
Output is correct |
37 |
Correct |
14 ms |
31700 KB |
Output is correct |
38 |
Correct |
13 ms |
31588 KB |
Output is correct |
39 |
Correct |
13 ms |
31700 KB |
Output is correct |
40 |
Correct |
15 ms |
31700 KB |
Output is correct |
41 |
Correct |
14 ms |
31712 KB |
Output is correct |
42 |
Correct |
15 ms |
31700 KB |
Output is correct |
43 |
Correct |
14 ms |
31700 KB |
Output is correct |
44 |
Correct |
14 ms |
31700 KB |
Output is correct |
45 |
Correct |
14 ms |
31956 KB |
Output is correct |
46 |
Correct |
15 ms |
31944 KB |
Output is correct |
47 |
Correct |
17 ms |
31940 KB |
Output is correct |
48 |
Correct |
15 ms |
31956 KB |
Output is correct |
49 |
Correct |
14 ms |
32032 KB |
Output is correct |
50 |
Correct |
14 ms |
31968 KB |
Output is correct |
51 |
Correct |
14 ms |
31700 KB |
Output is correct |
52 |
Correct |
16 ms |
32100 KB |
Output is correct |
53 |
Correct |
16 ms |
32084 KB |
Output is correct |
54 |
Correct |
16 ms |
32148 KB |
Output is correct |
55 |
Correct |
17 ms |
32212 KB |
Output is correct |
56 |
Correct |
15 ms |
32100 KB |
Output is correct |
57 |
Correct |
13 ms |
31704 KB |
Output is correct |
58 |
Correct |
14 ms |
31700 KB |
Output is correct |
59 |
Correct |
15 ms |
31780 KB |
Output is correct |
60 |
Correct |
15 ms |
31668 KB |
Output is correct |
61 |
Correct |
14 ms |
31700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
31572 KB |
Output is correct |
2 |
Correct |
13 ms |
31572 KB |
Output is correct |
3 |
Correct |
13 ms |
31572 KB |
Output is correct |
4 |
Correct |
13 ms |
31572 KB |
Output is correct |
5 |
Correct |
14 ms |
31620 KB |
Output is correct |
6 |
Correct |
14 ms |
31604 KB |
Output is correct |
7 |
Correct |
13 ms |
31636 KB |
Output is correct |
8 |
Correct |
17 ms |
31660 KB |
Output is correct |
9 |
Correct |
17 ms |
31700 KB |
Output is correct |
10 |
Correct |
14 ms |
31572 KB |
Output is correct |
11 |
Correct |
13 ms |
31608 KB |
Output is correct |
12 |
Correct |
13 ms |
31604 KB |
Output is correct |
13 |
Correct |
13 ms |
31700 KB |
Output is correct |
14 |
Correct |
14 ms |
31572 KB |
Output is correct |
15 |
Correct |
13 ms |
31700 KB |
Output is correct |
16 |
Correct |
14 ms |
31612 KB |
Output is correct |
17 |
Correct |
17 ms |
31700 KB |
Output is correct |
18 |
Correct |
14 ms |
31700 KB |
Output is correct |
19 |
Correct |
13 ms |
31700 KB |
Output is correct |
20 |
Correct |
16 ms |
31700 KB |
Output is correct |
21 |
Correct |
13 ms |
31692 KB |
Output is correct |
22 |
Correct |
14 ms |
31660 KB |
Output is correct |
23 |
Correct |
14 ms |
31624 KB |
Output is correct |
24 |
Correct |
17 ms |
31700 KB |
Output is correct |
25 |
Correct |
14 ms |
31588 KB |
Output is correct |
26 |
Correct |
16 ms |
31584 KB |
Output is correct |
27 |
Correct |
14 ms |
31688 KB |
Output is correct |
28 |
Correct |
13 ms |
31700 KB |
Output is correct |
29 |
Correct |
15 ms |
31636 KB |
Output is correct |
30 |
Correct |
15 ms |
31600 KB |
Output is correct |
31 |
Correct |
14 ms |
31700 KB |
Output is correct |
32 |
Correct |
14 ms |
31620 KB |
Output is correct |
33 |
Correct |
14 ms |
31584 KB |
Output is correct |
34 |
Correct |
14 ms |
31700 KB |
Output is correct |
35 |
Correct |
13 ms |
31600 KB |
Output is correct |
36 |
Correct |
14 ms |
31700 KB |
Output is correct |
37 |
Correct |
14 ms |
31700 KB |
Output is correct |
38 |
Correct |
13 ms |
31588 KB |
Output is correct |
39 |
Correct |
13 ms |
31700 KB |
Output is correct |
40 |
Correct |
15 ms |
31700 KB |
Output is correct |
41 |
Correct |
14 ms |
31712 KB |
Output is correct |
42 |
Correct |
15 ms |
31700 KB |
Output is correct |
43 |
Correct |
14 ms |
31700 KB |
Output is correct |
44 |
Correct |
14 ms |
31700 KB |
Output is correct |
45 |
Correct |
14 ms |
31956 KB |
Output is correct |
46 |
Correct |
15 ms |
31944 KB |
Output is correct |
47 |
Correct |
17 ms |
31940 KB |
Output is correct |
48 |
Correct |
15 ms |
31956 KB |
Output is correct |
49 |
Correct |
14 ms |
32032 KB |
Output is correct |
50 |
Correct |
14 ms |
31968 KB |
Output is correct |
51 |
Correct |
14 ms |
31700 KB |
Output is correct |
52 |
Correct |
16 ms |
32100 KB |
Output is correct |
53 |
Correct |
16 ms |
32084 KB |
Output is correct |
54 |
Correct |
16 ms |
32148 KB |
Output is correct |
55 |
Correct |
17 ms |
32212 KB |
Output is correct |
56 |
Correct |
15 ms |
32100 KB |
Output is correct |
57 |
Correct |
13 ms |
31704 KB |
Output is correct |
58 |
Correct |
14 ms |
31700 KB |
Output is correct |
59 |
Correct |
15 ms |
31780 KB |
Output is correct |
60 |
Correct |
15 ms |
31668 KB |
Output is correct |
61 |
Correct |
14 ms |
31700 KB |
Output is correct |
62 |
Correct |
21 ms |
31852 KB |
Output is correct |
63 |
Correct |
34 ms |
31980 KB |
Output is correct |
64 |
Correct |
33 ms |
31948 KB |
Output is correct |
65 |
Correct |
32 ms |
31992 KB |
Output is correct |
66 |
Correct |
30 ms |
31912 KB |
Output is correct |
67 |
Correct |
39 ms |
31948 KB |
Output is correct |
68 |
Correct |
30 ms |
31956 KB |
Output is correct |
69 |
Correct |
33 ms |
31976 KB |
Output is correct |
70 |
Correct |
34 ms |
44788 KB |
Output is correct |
71 |
Correct |
35 ms |
45272 KB |
Output is correct |
72 |
Correct |
36 ms |
44456 KB |
Output is correct |
73 |
Correct |
36 ms |
44616 KB |
Output is correct |
74 |
Correct |
44 ms |
44924 KB |
Output is correct |
75 |
Correct |
35 ms |
44788 KB |
Output is correct |
76 |
Correct |
28 ms |
31908 KB |
Output is correct |
77 |
Correct |
90 ms |
51868 KB |
Output is correct |
78 |
Correct |
83 ms |
51852 KB |
Output is correct |
79 |
Correct |
96 ms |
51916 KB |
Output is correct |
80 |
Correct |
97 ms |
51904 KB |
Output is correct |
81 |
Correct |
92 ms |
51900 KB |
Output is correct |
82 |
Correct |
22 ms |
31820 KB |
Output is correct |
83 |
Correct |
36 ms |
33280 KB |
Output is correct |
84 |
Correct |
33 ms |
32844 KB |
Output is correct |
85 |
Correct |
29 ms |
31924 KB |
Output is correct |
86 |
Correct |
29 ms |
31944 KB |
Output is correct |