#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-- )
if( r == n || (ponto[meuUltimo[i]] - ponto[i]) % (ponto[r]-ponto[i]) >= 0 )
{
if(meuUltimo[i] + 1 <= r-1 )
dp[i][r-1] += maxSuf[ meuUltimo[i]+1 ] ;
maxSuf[i] = max(maxSuf[i] , maxSuf[i+1]) ;
maxSuf[i] = max(maxSuf[i] ,dp[i][r-1] ) ;
meuUltimo[i] = r ;
}
}
int mx = 1 ;
for(int i = 0 ; i < n ; i++ ) mx = max(mx, *max_element(dp[i].begin() , dp[i].end())) ;
return mx ;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
0 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
0 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
10 |
Correct |
1 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 |
1 ms |
256 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
0 ms |
256 KB |
Output is correct |
16 |
Correct |
0 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
0 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
0 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
10 |
Correct |
1 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 |
1 ms |
256 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
0 ms |
256 KB |
Output is correct |
16 |
Correct |
0 ms |
256 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
19 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
0 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
0 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
10 |
Correct |
1 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 |
1 ms |
256 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
0 ms |
256 KB |
Output is correct |
16 |
Correct |
0 ms |
256 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
19 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
0 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
0 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
10 |
Correct |
1 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 |
1 ms |
256 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
0 ms |
256 KB |
Output is correct |
16 |
Correct |
0 ms |
256 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
19 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |