#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( i == 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] ,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 ;
}
# |
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 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |