#include "mountains.h"
#include <bits/stdc++.h>
#define ll long long
#define sz(x) (int)(x.size())
using namespace std ;
template<class T>
class Point
{
public:
T x , y ;
Point(){ x = y = 0 ; }
Point(T a, T b)
{
x = a ;
y = b ;
}
T operator % (Point other) const { return x*other.y - y*other.x ; }
T operator * (Point other) const { return x*other.x + y*other.y ; }
Point operator - (Point other) const { return Point(x-other.x, y-other.y) ; }
} ;
int maximum_deevs(vector<int> y)
{
int n = sz(y) ;
vector< Point<ll> > ponto(n) ;
for(int i = 0 ; i< n ; i++ ) ponto[i].x = i , ponto[i].y = y[i] ;
vector< vector<int> > dp(n+5, vector<int>(n+5,0) ) ;
vector< int > meuUltimo(n) , maxSuf(n+5,0) ;
for(int i = 0 ; i < n ; i++ )
for(int j = i ; j < n ; j++ ) dp[i][j] = 1 ;
for(int i = 0 ; i <n-1 ; i++ ) meuUltimo[i] = i+1 ;
for(int r = 2 ; r <= n ; r++ )
{
for(int i = 0 ; i <= r-2 ; i++ )
dp[i][r-1] = dp[i][r-2] ;
for(int i = r-1 ; i >= 0 ; i-- ) maxSuf[i] = max(maxSuf[i+1] , dp[i][r-1] ) ;
for(int i = r-2 ; i >= 0 ; i-- )
{
maxSuf[i] = max(maxSuf[i+1] , maxSuf[i]) ;
dp[i][r-1] = max(dp[i][r-1], dp[i][ meuUltimo[i]-1 ] + maxSuf[ meuUltimo[i]+1 ] ) ;
if( r == n || (ponto[meuUltimo[i]] - ponto[i]) % (ponto[r]-ponto[i]) >= 0 )
meuUltimo[i] = r ;
maxSuf[i] = max(maxSuf[i] ,dp[i][r-1] ) ;
}
}
int mx = 1 ;
for(int i = 0 ; i < n ; i++ ) mx = max(mx, *max_element(dp[i].begin() , dp[i].end())) ;
return mx ;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
1 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
0 ms |
256 KB |
Output is correct |
10 |
Correct |
0 ms |
256 KB |
Output is correct |
11 |
Correct |
1 ms |
256 KB |
Output is correct |
12 |
Correct |
0 ms |
256 KB |
Output is correct |
13 |
Correct |
0 ms |
256 KB |
Output is correct |
14 |
Correct |
0 ms |
256 KB |
Output is correct |
15 |
Correct |
0 ms |
256 KB |
Output is correct |
16 |
Correct |
1 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
1 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
0 ms |
256 KB |
Output is correct |
10 |
Correct |
0 ms |
256 KB |
Output is correct |
11 |
Correct |
1 ms |
256 KB |
Output is correct |
12 |
Correct |
0 ms |
256 KB |
Output is correct |
13 |
Correct |
0 ms |
256 KB |
Output is correct |
14 |
Correct |
0 ms |
256 KB |
Output is correct |
15 |
Correct |
0 ms |
256 KB |
Output is correct |
16 |
Correct |
1 ms |
256 KB |
Output is correct |
17 |
Correct |
0 ms |
256 KB |
Output is correct |
18 |
Correct |
0 ms |
256 KB |
Output is correct |
19 |
Correct |
0 ms |
256 KB |
Output is correct |
20 |
Correct |
1 ms |
256 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
256 KB |
Output is correct |
25 |
Correct |
0 ms |
256 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
384 KB |
Output is correct |
28 |
Correct |
1 ms |
384 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
1 ms |
384 KB |
Output is correct |
31 |
Correct |
1 ms |
384 KB |
Output is correct |
32 |
Correct |
1 ms |
384 KB |
Output is correct |
33 |
Correct |
1 ms |
368 KB |
Output is correct |
34 |
Correct |
1 ms |
512 KB |
Output is correct |
35 |
Correct |
0 ms |
256 KB |
Output is correct |
36 |
Correct |
0 ms |
256 KB |
Output is correct |
37 |
Correct |
1 ms |
384 KB |
Output is correct |
38 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
1 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
0 ms |
256 KB |
Output is correct |
10 |
Correct |
0 ms |
256 KB |
Output is correct |
11 |
Correct |
1 ms |
256 KB |
Output is correct |
12 |
Correct |
0 ms |
256 KB |
Output is correct |
13 |
Correct |
0 ms |
256 KB |
Output is correct |
14 |
Correct |
0 ms |
256 KB |
Output is correct |
15 |
Correct |
0 ms |
256 KB |
Output is correct |
16 |
Correct |
1 ms |
256 KB |
Output is correct |
17 |
Correct |
0 ms |
256 KB |
Output is correct |
18 |
Correct |
0 ms |
256 KB |
Output is correct |
19 |
Correct |
0 ms |
256 KB |
Output is correct |
20 |
Correct |
1 ms |
256 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
256 KB |
Output is correct |
25 |
Correct |
0 ms |
256 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
384 KB |
Output is correct |
28 |
Correct |
1 ms |
384 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
1 ms |
384 KB |
Output is correct |
31 |
Correct |
1 ms |
384 KB |
Output is correct |
32 |
Correct |
1 ms |
384 KB |
Output is correct |
33 |
Correct |
1 ms |
368 KB |
Output is correct |
34 |
Correct |
1 ms |
512 KB |
Output is correct |
35 |
Correct |
0 ms |
256 KB |
Output is correct |
36 |
Correct |
0 ms |
256 KB |
Output is correct |
37 |
Correct |
1 ms |
384 KB |
Output is correct |
38 |
Correct |
1 ms |
384 KB |
Output is correct |
39 |
Correct |
1 ms |
512 KB |
Output is correct |
40 |
Correct |
2 ms |
640 KB |
Output is correct |
41 |
Correct |
2 ms |
640 KB |
Output is correct |
42 |
Correct |
2 ms |
640 KB |
Output is correct |
43 |
Correct |
2 ms |
640 KB |
Output is correct |
44 |
Correct |
2 ms |
640 KB |
Output is correct |
45 |
Correct |
2 ms |
640 KB |
Output is correct |
46 |
Correct |
1 ms |
640 KB |
Output is correct |
47 |
Correct |
2 ms |
640 KB |
Output is correct |
48 |
Correct |
2 ms |
640 KB |
Output is correct |
49 |
Correct |
2 ms |
640 KB |
Output is correct |
50 |
Correct |
2 ms |
640 KB |
Output is correct |
51 |
Correct |
2 ms |
640 KB |
Output is correct |
52 |
Correct |
2 ms |
640 KB |
Output is correct |
53 |
Correct |
2 ms |
640 KB |
Output is correct |
54 |
Correct |
2 ms |
640 KB |
Output is correct |
55 |
Correct |
2 ms |
640 KB |
Output is correct |
56 |
Correct |
2 ms |
640 KB |
Output is correct |
57 |
Correct |
2 ms |
768 KB |
Output is correct |
58 |
Correct |
2 ms |
640 KB |
Output is correct |
59 |
Correct |
2 ms |
640 KB |
Output is correct |
60 |
Correct |
2 ms |
640 KB |
Output is correct |
61 |
Correct |
2 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
1 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
0 ms |
256 KB |
Output is correct |
10 |
Correct |
0 ms |
256 KB |
Output is correct |
11 |
Correct |
1 ms |
256 KB |
Output is correct |
12 |
Correct |
0 ms |
256 KB |
Output is correct |
13 |
Correct |
0 ms |
256 KB |
Output is correct |
14 |
Correct |
0 ms |
256 KB |
Output is correct |
15 |
Correct |
0 ms |
256 KB |
Output is correct |
16 |
Correct |
1 ms |
256 KB |
Output is correct |
17 |
Correct |
0 ms |
256 KB |
Output is correct |
18 |
Correct |
0 ms |
256 KB |
Output is correct |
19 |
Correct |
0 ms |
256 KB |
Output is correct |
20 |
Correct |
1 ms |
256 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
256 KB |
Output is correct |
25 |
Correct |
0 ms |
256 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
384 KB |
Output is correct |
28 |
Correct |
1 ms |
384 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
1 ms |
384 KB |
Output is correct |
31 |
Correct |
1 ms |
384 KB |
Output is correct |
32 |
Correct |
1 ms |
384 KB |
Output is correct |
33 |
Correct |
1 ms |
368 KB |
Output is correct |
34 |
Correct |
1 ms |
512 KB |
Output is correct |
35 |
Correct |
0 ms |
256 KB |
Output is correct |
36 |
Correct |
0 ms |
256 KB |
Output is correct |
37 |
Correct |
1 ms |
384 KB |
Output is correct |
38 |
Correct |
1 ms |
384 KB |
Output is correct |
39 |
Correct |
1 ms |
512 KB |
Output is correct |
40 |
Correct |
2 ms |
640 KB |
Output is correct |
41 |
Correct |
2 ms |
640 KB |
Output is correct |
42 |
Correct |
2 ms |
640 KB |
Output is correct |
43 |
Correct |
2 ms |
640 KB |
Output is correct |
44 |
Correct |
2 ms |
640 KB |
Output is correct |
45 |
Correct |
2 ms |
640 KB |
Output is correct |
46 |
Correct |
1 ms |
640 KB |
Output is correct |
47 |
Correct |
2 ms |
640 KB |
Output is correct |
48 |
Correct |
2 ms |
640 KB |
Output is correct |
49 |
Correct |
2 ms |
640 KB |
Output is correct |
50 |
Correct |
2 ms |
640 KB |
Output is correct |
51 |
Correct |
2 ms |
640 KB |
Output is correct |
52 |
Correct |
2 ms |
640 KB |
Output is correct |
53 |
Correct |
2 ms |
640 KB |
Output is correct |
54 |
Correct |
2 ms |
640 KB |
Output is correct |
55 |
Correct |
2 ms |
640 KB |
Output is correct |
56 |
Correct |
2 ms |
640 KB |
Output is correct |
57 |
Correct |
2 ms |
768 KB |
Output is correct |
58 |
Correct |
2 ms |
640 KB |
Output is correct |
59 |
Correct |
2 ms |
640 KB |
Output is correct |
60 |
Correct |
2 ms |
640 KB |
Output is correct |
61 |
Correct |
2 ms |
640 KB |
Output is correct |
62 |
Correct |
12 ms |
4352 KB |
Output is correct |
63 |
Correct |
74 ms |
16256 KB |
Output is correct |
64 |
Correct |
76 ms |
16128 KB |
Output is correct |
65 |
Correct |
75 ms |
16128 KB |
Output is correct |
66 |
Correct |
74 ms |
16128 KB |
Output is correct |
67 |
Correct |
74 ms |
16128 KB |
Output is correct |
68 |
Correct |
74 ms |
16128 KB |
Output is correct |
69 |
Correct |
75 ms |
16128 KB |
Output is correct |
70 |
Correct |
66 ms |
16128 KB |
Output is correct |
71 |
Correct |
66 ms |
16128 KB |
Output is correct |
72 |
Correct |
68 ms |
16128 KB |
Output is correct |
73 |
Correct |
67 ms |
16128 KB |
Output is correct |
74 |
Correct |
66 ms |
16128 KB |
Output is correct |
75 |
Correct |
68 ms |
16128 KB |
Output is correct |
76 |
Correct |
74 ms |
16128 KB |
Output is correct |
77 |
Correct |
63 ms |
16248 KB |
Output is correct |
78 |
Correct |
61 ms |
16128 KB |
Output is correct |
79 |
Correct |
61 ms |
16128 KB |
Output is correct |
80 |
Correct |
63 ms |
16128 KB |
Output is correct |
81 |
Correct |
63 ms |
16128 KB |
Output is correct |
82 |
Correct |
77 ms |
16128 KB |
Output is correct |
83 |
Correct |
75 ms |
16128 KB |
Output is correct |
84 |
Correct |
76 ms |
16128 KB |
Output is correct |
85 |
Correct |
76 ms |
16248 KB |
Output is correct |
86 |
Correct |
76 ms |
16256 KB |
Output is correct |