#include "mountains.h"
#include <bits/stdc++.h>
using namespace std ;
const int MAX = 2005 ;
int dp[MAX][MAX] ;
int n ;
vector<int>v ;
/*long double slope(int a , int b , int a2 , int b2)
{
long double x = a * 1.0000 ;
long double y = b * 1.0000 ;
long double x2 = a2 * 1.0000 ;
long double y2 = b2 * 1.0000 ;
return ((y2-y) / (x2-x)) ;
}*/
bool check(int a,int b,int c)
{
return 1ll * (v[a]*1ll - v[b] * 1ll) * (a*1ll - c*1ll) > 1ll * (v[a] * 1ll - v[c] * 1ll) * (a * 1ll - b * 1ll);
}
int solve(int l , int r)
{
if(l >= r)
return (l == r) ;
int &ret = dp[l][r] ;
if(ret != -1)
return ret ;
int MAX = 0 , idx = l ;
for(int i = l ; i <= r ; ++i)
{
if(v[i] > MAX)
MAX = v[i] , idx = i ;
}
int choice1 = solve(l , idx-1) + solve(idx+1 , r) ;
int choice2 = 0;
int last = idx+1 ;
for(int i = last ; i <= r ; ++i)
{
i = last ;
for(int j = i+1 ; j <= r ; ++j)
{
last = j ;
if(!check(idx , i , j))
{
choice2 += solve(i+1 , j-1) ;
break;
}
}
if(last == r && check(idx , i , r))
choice2 += solve(i+1 , r) ;
}
last = idx - 1 ;
for(int i = last ; i >= l ; --i)
{
i = last ;
for(int j = i-1 ; j >= l ; --j)
{
last = j ;
if(!check(j , i , idx))
{
choice2 += solve(j+1 , i-1) ;
break;
}
}
if(last == l && check(l , i , idx))
choice2 += solve(l , i-1) ;
}
choice2++ ;
ret = max(choice1 , choice2) ;
return ret ;
}
int maximum_deevs(vector<int>x)
{
memset(dp , -1 , sizeof(dp)) ;
v = x ;
n = v.size() ;
return solve(0 , n-1) ;
}
/*int main()
{
int n ;
cin>>n ;
vector<int>x(n) ;
for(auto &i : x)
cin>>i ;
cout<<maximum_deevs(x)<<"\n" ;
return 0 ;
}*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
16000 KB |
Output is correct |
2 |
Correct |
14 ms |
16000 KB |
Output is correct |
3 |
Correct |
13 ms |
16000 KB |
Output is correct |
4 |
Correct |
14 ms |
16128 KB |
Output is correct |
5 |
Correct |
13 ms |
16128 KB |
Output is correct |
6 |
Correct |
13 ms |
16128 KB |
Output is correct |
7 |
Correct |
13 ms |
16128 KB |
Output is correct |
8 |
Correct |
13 ms |
16128 KB |
Output is correct |
9 |
Correct |
13 ms |
16128 KB |
Output is correct |
10 |
Correct |
14 ms |
16000 KB |
Output is correct |
11 |
Correct |
14 ms |
16076 KB |
Output is correct |
12 |
Correct |
13 ms |
16000 KB |
Output is correct |
13 |
Correct |
13 ms |
16100 KB |
Output is correct |
14 |
Correct |
13 ms |
16000 KB |
Output is correct |
15 |
Correct |
13 ms |
16128 KB |
Output is correct |
16 |
Correct |
13 ms |
16100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
16000 KB |
Output is correct |
2 |
Correct |
14 ms |
16000 KB |
Output is correct |
3 |
Correct |
13 ms |
16000 KB |
Output is correct |
4 |
Correct |
14 ms |
16128 KB |
Output is correct |
5 |
Correct |
13 ms |
16128 KB |
Output is correct |
6 |
Correct |
13 ms |
16128 KB |
Output is correct |
7 |
Correct |
13 ms |
16128 KB |
Output is correct |
8 |
Correct |
13 ms |
16128 KB |
Output is correct |
9 |
Correct |
13 ms |
16128 KB |
Output is correct |
10 |
Correct |
14 ms |
16000 KB |
Output is correct |
11 |
Correct |
14 ms |
16076 KB |
Output is correct |
12 |
Correct |
13 ms |
16000 KB |
Output is correct |
13 |
Correct |
13 ms |
16100 KB |
Output is correct |
14 |
Correct |
13 ms |
16000 KB |
Output is correct |
15 |
Correct |
13 ms |
16128 KB |
Output is correct |
16 |
Correct |
13 ms |
16100 KB |
Output is correct |
17 |
Correct |
13 ms |
16000 KB |
Output is correct |
18 |
Correct |
14 ms |
16084 KB |
Output is correct |
19 |
Correct |
14 ms |
16128 KB |
Output is correct |
20 |
Correct |
14 ms |
16000 KB |
Output is correct |
21 |
Correct |
14 ms |
16120 KB |
Output is correct |
22 |
Correct |
14 ms |
16128 KB |
Output is correct |
23 |
Correct |
13 ms |
16128 KB |
Output is correct |
24 |
Correct |
13 ms |
16128 KB |
Output is correct |
25 |
Correct |
14 ms |
16000 KB |
Output is correct |
26 |
Correct |
14 ms |
16064 KB |
Output is correct |
27 |
Correct |
13 ms |
16000 KB |
Output is correct |
28 |
Correct |
14 ms |
16000 KB |
Output is correct |
29 |
Correct |
35 ms |
16000 KB |
Output is correct |
30 |
Correct |
13 ms |
16128 KB |
Output is correct |
31 |
Correct |
14 ms |
16000 KB |
Output is correct |
32 |
Correct |
14 ms |
16000 KB |
Output is correct |
33 |
Correct |
14 ms |
16000 KB |
Output is correct |
34 |
Correct |
14 ms |
15984 KB |
Output is correct |
35 |
Correct |
14 ms |
16128 KB |
Output is correct |
36 |
Correct |
14 ms |
16000 KB |
Output is correct |
37 |
Correct |
13 ms |
16000 KB |
Output is correct |
38 |
Correct |
14 ms |
16000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
16000 KB |
Output is correct |
2 |
Correct |
14 ms |
16000 KB |
Output is correct |
3 |
Correct |
13 ms |
16000 KB |
Output is correct |
4 |
Correct |
14 ms |
16128 KB |
Output is correct |
5 |
Correct |
13 ms |
16128 KB |
Output is correct |
6 |
Correct |
13 ms |
16128 KB |
Output is correct |
7 |
Correct |
13 ms |
16128 KB |
Output is correct |
8 |
Correct |
13 ms |
16128 KB |
Output is correct |
9 |
Correct |
13 ms |
16128 KB |
Output is correct |
10 |
Correct |
14 ms |
16000 KB |
Output is correct |
11 |
Correct |
14 ms |
16076 KB |
Output is correct |
12 |
Correct |
13 ms |
16000 KB |
Output is correct |
13 |
Correct |
13 ms |
16100 KB |
Output is correct |
14 |
Correct |
13 ms |
16000 KB |
Output is correct |
15 |
Correct |
13 ms |
16128 KB |
Output is correct |
16 |
Correct |
13 ms |
16100 KB |
Output is correct |
17 |
Correct |
13 ms |
16000 KB |
Output is correct |
18 |
Correct |
14 ms |
16084 KB |
Output is correct |
19 |
Correct |
14 ms |
16128 KB |
Output is correct |
20 |
Correct |
14 ms |
16000 KB |
Output is correct |
21 |
Correct |
14 ms |
16120 KB |
Output is correct |
22 |
Correct |
14 ms |
16128 KB |
Output is correct |
23 |
Correct |
13 ms |
16128 KB |
Output is correct |
24 |
Correct |
13 ms |
16128 KB |
Output is correct |
25 |
Correct |
14 ms |
16000 KB |
Output is correct |
26 |
Correct |
14 ms |
16064 KB |
Output is correct |
27 |
Correct |
13 ms |
16000 KB |
Output is correct |
28 |
Correct |
14 ms |
16000 KB |
Output is correct |
29 |
Correct |
35 ms |
16000 KB |
Output is correct |
30 |
Correct |
13 ms |
16128 KB |
Output is correct |
31 |
Correct |
14 ms |
16000 KB |
Output is correct |
32 |
Correct |
14 ms |
16000 KB |
Output is correct |
33 |
Correct |
14 ms |
16000 KB |
Output is correct |
34 |
Correct |
14 ms |
15984 KB |
Output is correct |
35 |
Correct |
14 ms |
16128 KB |
Output is correct |
36 |
Correct |
14 ms |
16000 KB |
Output is correct |
37 |
Correct |
13 ms |
16000 KB |
Output is correct |
38 |
Correct |
14 ms |
16000 KB |
Output is correct |
39 |
Correct |
14 ms |
16128 KB |
Output is correct |
40 |
Correct |
13 ms |
16128 KB |
Output is correct |
41 |
Correct |
14 ms |
16128 KB |
Output is correct |
42 |
Correct |
14 ms |
16000 KB |
Output is correct |
43 |
Correct |
14 ms |
16128 KB |
Output is correct |
44 |
Correct |
13 ms |
16000 KB |
Output is correct |
45 |
Correct |
14 ms |
16128 KB |
Output is correct |
46 |
Correct |
14 ms |
16012 KB |
Output is correct |
47 |
Correct |
14 ms |
16128 KB |
Output is correct |
48 |
Correct |
14 ms |
16128 KB |
Output is correct |
49 |
Correct |
14 ms |
16000 KB |
Output is correct |
50 |
Correct |
14 ms |
16000 KB |
Output is correct |
51 |
Correct |
20 ms |
16000 KB |
Output is correct |
52 |
Correct |
15 ms |
16128 KB |
Output is correct |
53 |
Correct |
15 ms |
16128 KB |
Output is correct |
54 |
Correct |
23 ms |
16128 KB |
Output is correct |
55 |
Correct |
16 ms |
16128 KB |
Output is correct |
56 |
Correct |
15 ms |
16044 KB |
Output is correct |
57 |
Correct |
14 ms |
16128 KB |
Output is correct |
58 |
Correct |
13 ms |
16000 KB |
Output is correct |
59 |
Correct |
14 ms |
16128 KB |
Output is correct |
60 |
Correct |
14 ms |
16128 KB |
Output is correct |
61 |
Correct |
14 ms |
16128 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
16000 KB |
Output is correct |
2 |
Correct |
14 ms |
16000 KB |
Output is correct |
3 |
Correct |
13 ms |
16000 KB |
Output is correct |
4 |
Correct |
14 ms |
16128 KB |
Output is correct |
5 |
Correct |
13 ms |
16128 KB |
Output is correct |
6 |
Correct |
13 ms |
16128 KB |
Output is correct |
7 |
Correct |
13 ms |
16128 KB |
Output is correct |
8 |
Correct |
13 ms |
16128 KB |
Output is correct |
9 |
Correct |
13 ms |
16128 KB |
Output is correct |
10 |
Correct |
14 ms |
16000 KB |
Output is correct |
11 |
Correct |
14 ms |
16076 KB |
Output is correct |
12 |
Correct |
13 ms |
16000 KB |
Output is correct |
13 |
Correct |
13 ms |
16100 KB |
Output is correct |
14 |
Correct |
13 ms |
16000 KB |
Output is correct |
15 |
Correct |
13 ms |
16128 KB |
Output is correct |
16 |
Correct |
13 ms |
16100 KB |
Output is correct |
17 |
Correct |
13 ms |
16000 KB |
Output is correct |
18 |
Correct |
14 ms |
16084 KB |
Output is correct |
19 |
Correct |
14 ms |
16128 KB |
Output is correct |
20 |
Correct |
14 ms |
16000 KB |
Output is correct |
21 |
Correct |
14 ms |
16120 KB |
Output is correct |
22 |
Correct |
14 ms |
16128 KB |
Output is correct |
23 |
Correct |
13 ms |
16128 KB |
Output is correct |
24 |
Correct |
13 ms |
16128 KB |
Output is correct |
25 |
Correct |
14 ms |
16000 KB |
Output is correct |
26 |
Correct |
14 ms |
16064 KB |
Output is correct |
27 |
Correct |
13 ms |
16000 KB |
Output is correct |
28 |
Correct |
14 ms |
16000 KB |
Output is correct |
29 |
Correct |
35 ms |
16000 KB |
Output is correct |
30 |
Correct |
13 ms |
16128 KB |
Output is correct |
31 |
Correct |
14 ms |
16000 KB |
Output is correct |
32 |
Correct |
14 ms |
16000 KB |
Output is correct |
33 |
Correct |
14 ms |
16000 KB |
Output is correct |
34 |
Correct |
14 ms |
15984 KB |
Output is correct |
35 |
Correct |
14 ms |
16128 KB |
Output is correct |
36 |
Correct |
14 ms |
16000 KB |
Output is correct |
37 |
Correct |
13 ms |
16000 KB |
Output is correct |
38 |
Correct |
14 ms |
16000 KB |
Output is correct |
39 |
Correct |
14 ms |
16128 KB |
Output is correct |
40 |
Correct |
13 ms |
16128 KB |
Output is correct |
41 |
Correct |
14 ms |
16128 KB |
Output is correct |
42 |
Correct |
14 ms |
16000 KB |
Output is correct |
43 |
Correct |
14 ms |
16128 KB |
Output is correct |
44 |
Correct |
13 ms |
16000 KB |
Output is correct |
45 |
Correct |
14 ms |
16128 KB |
Output is correct |
46 |
Correct |
14 ms |
16012 KB |
Output is correct |
47 |
Correct |
14 ms |
16128 KB |
Output is correct |
48 |
Correct |
14 ms |
16128 KB |
Output is correct |
49 |
Correct |
14 ms |
16000 KB |
Output is correct |
50 |
Correct |
14 ms |
16000 KB |
Output is correct |
51 |
Correct |
20 ms |
16000 KB |
Output is correct |
52 |
Correct |
15 ms |
16128 KB |
Output is correct |
53 |
Correct |
15 ms |
16128 KB |
Output is correct |
54 |
Correct |
23 ms |
16128 KB |
Output is correct |
55 |
Correct |
16 ms |
16128 KB |
Output is correct |
56 |
Correct |
15 ms |
16044 KB |
Output is correct |
57 |
Correct |
14 ms |
16128 KB |
Output is correct |
58 |
Correct |
13 ms |
16000 KB |
Output is correct |
59 |
Correct |
14 ms |
16128 KB |
Output is correct |
60 |
Correct |
14 ms |
16128 KB |
Output is correct |
61 |
Correct |
14 ms |
16128 KB |
Output is correct |
62 |
Correct |
14 ms |
16128 KB |
Output is correct |
63 |
Correct |
14 ms |
16128 KB |
Output is correct |
64 |
Correct |
14 ms |
16044 KB |
Output is correct |
65 |
Correct |
14 ms |
16128 KB |
Output is correct |
66 |
Correct |
15 ms |
16064 KB |
Output is correct |
67 |
Correct |
15 ms |
16128 KB |
Output is correct |
68 |
Correct |
14 ms |
16100 KB |
Output is correct |
69 |
Correct |
14 ms |
16256 KB |
Output is correct |
70 |
Correct |
18 ms |
16256 KB |
Output is correct |
71 |
Correct |
18 ms |
16256 KB |
Output is correct |
72 |
Correct |
18 ms |
16256 KB |
Output is correct |
73 |
Correct |
18 ms |
16256 KB |
Output is correct |
74 |
Correct |
18 ms |
16256 KB |
Output is correct |
75 |
Correct |
19 ms |
16256 KB |
Output is correct |
76 |
Correct |
13 ms |
16156 KB |
Output is correct |
77 |
Correct |
31 ms |
16384 KB |
Output is correct |
78 |
Correct |
29 ms |
16384 KB |
Output is correct |
79 |
Correct |
31 ms |
16384 KB |
Output is correct |
80 |
Correct |
30 ms |
16384 KB |
Output is correct |
81 |
Correct |
30 ms |
16384 KB |
Output is correct |
82 |
Correct |
18 ms |
16384 KB |
Output is correct |
83 |
Correct |
21 ms |
16128 KB |
Output is correct |
84 |
Correct |
19 ms |
16128 KB |
Output is correct |
85 |
Correct |
18 ms |
16384 KB |
Output is correct |
86 |
Correct |
18 ms |
16376 KB |
Output is correct |