#include "mountains.h"
#include <vector>
#define x first
#define y second
const int NMAX = 2000;
int N;
int dp[NMAX + 5][NMAX + 5];
int vf;
std::pair <int, int> st[NMAX + 5];
bool ccw(std::pair <int, int> a, std::pair <int, int> b, std::pair <int, int> c) {
return (1LL * a.first * (b.second - c.second) + 1LL * b.first * (c.second - a.second) + 1LL * c.first * (a.second - b.second) <= 0);
}
void Push(std::pair <int, int> dot) {
while(vf > 1 && ccw(st[vf], st[vf - 1], dot))
vf--;
st[++vf] = dot;
}
int maximum_deevs(std::vector<int> y) {
N = (int)y.size();
for(int i = N; i >= 1; i--) {
vf = 0;
for(int j = i; j <= N; j++) {
Push({j, y[j - 1]});
dp[i][j] = 1;
if(vf >= 1) {
int t = st[vf].first;
dp[i][j] = std::max(dp[i][j], dp[i][t - 1] + dp[t + 1][j]);
}
if(vf > 1) {
int s = st[vf - 1].first;
dp[i][j] = std::max(dp[i][j], dp[i][s - 1] + dp[s + 1][j]);
}
}
}
return dp[1][N];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
0 ms |
364 KB |
Output is correct |
10 |
Correct |
0 ms |
364 KB |
Output is correct |
11 |
Correct |
0 ms |
364 KB |
Output is correct |
12 |
Correct |
0 ms |
364 KB |
Output is correct |
13 |
Correct |
0 ms |
364 KB |
Output is correct |
14 |
Correct |
0 ms |
364 KB |
Output is correct |
15 |
Correct |
0 ms |
364 KB |
Output is correct |
16 |
Correct |
0 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
0 ms |
364 KB |
Output is correct |
10 |
Correct |
0 ms |
364 KB |
Output is correct |
11 |
Correct |
0 ms |
364 KB |
Output is correct |
12 |
Correct |
0 ms |
364 KB |
Output is correct |
13 |
Correct |
0 ms |
364 KB |
Output is correct |
14 |
Correct |
0 ms |
364 KB |
Output is correct |
15 |
Correct |
0 ms |
364 KB |
Output is correct |
16 |
Correct |
0 ms |
364 KB |
Output is correct |
17 |
Correct |
0 ms |
492 KB |
Output is correct |
18 |
Correct |
0 ms |
492 KB |
Output is correct |
19 |
Correct |
1 ms |
492 KB |
Output is correct |
20 |
Correct |
1 ms |
492 KB |
Output is correct |
21 |
Correct |
1 ms |
492 KB |
Output is correct |
22 |
Correct |
1 ms |
492 KB |
Output is correct |
23 |
Correct |
1 ms |
492 KB |
Output is correct |
24 |
Correct |
1 ms |
492 KB |
Output is correct |
25 |
Correct |
1 ms |
492 KB |
Output is correct |
26 |
Correct |
0 ms |
492 KB |
Output is correct |
27 |
Correct |
0 ms |
492 KB |
Output is correct |
28 |
Correct |
1 ms |
492 KB |
Output is correct |
29 |
Correct |
0 ms |
492 KB |
Output is correct |
30 |
Correct |
1 ms |
492 KB |
Output is correct |
31 |
Correct |
0 ms |
492 KB |
Output is correct |
32 |
Correct |
0 ms |
492 KB |
Output is correct |
33 |
Correct |
0 ms |
492 KB |
Output is correct |
34 |
Correct |
1 ms |
492 KB |
Output is correct |
35 |
Correct |
1 ms |
492 KB |
Output is correct |
36 |
Correct |
0 ms |
492 KB |
Output is correct |
37 |
Correct |
1 ms |
492 KB |
Output is correct |
38 |
Correct |
0 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
0 ms |
364 KB |
Output is correct |
10 |
Correct |
0 ms |
364 KB |
Output is correct |
11 |
Correct |
0 ms |
364 KB |
Output is correct |
12 |
Correct |
0 ms |
364 KB |
Output is correct |
13 |
Correct |
0 ms |
364 KB |
Output is correct |
14 |
Correct |
0 ms |
364 KB |
Output is correct |
15 |
Correct |
0 ms |
364 KB |
Output is correct |
16 |
Correct |
0 ms |
364 KB |
Output is correct |
17 |
Correct |
0 ms |
492 KB |
Output is correct |
18 |
Correct |
0 ms |
492 KB |
Output is correct |
19 |
Correct |
1 ms |
492 KB |
Output is correct |
20 |
Correct |
1 ms |
492 KB |
Output is correct |
21 |
Correct |
1 ms |
492 KB |
Output is correct |
22 |
Correct |
1 ms |
492 KB |
Output is correct |
23 |
Correct |
1 ms |
492 KB |
Output is correct |
24 |
Correct |
1 ms |
492 KB |
Output is correct |
25 |
Correct |
1 ms |
492 KB |
Output is correct |
26 |
Correct |
0 ms |
492 KB |
Output is correct |
27 |
Correct |
0 ms |
492 KB |
Output is correct |
28 |
Correct |
1 ms |
492 KB |
Output is correct |
29 |
Correct |
0 ms |
492 KB |
Output is correct |
30 |
Correct |
1 ms |
492 KB |
Output is correct |
31 |
Correct |
0 ms |
492 KB |
Output is correct |
32 |
Correct |
0 ms |
492 KB |
Output is correct |
33 |
Correct |
0 ms |
492 KB |
Output is correct |
34 |
Correct |
1 ms |
492 KB |
Output is correct |
35 |
Correct |
1 ms |
492 KB |
Output is correct |
36 |
Correct |
0 ms |
492 KB |
Output is correct |
37 |
Correct |
1 ms |
492 KB |
Output is correct |
38 |
Correct |
0 ms |
492 KB |
Output is correct |
39 |
Correct |
1 ms |
1260 KB |
Output is correct |
40 |
Correct |
2 ms |
1644 KB |
Output is correct |
41 |
Correct |
2 ms |
1664 KB |
Output is correct |
42 |
Correct |
2 ms |
1644 KB |
Output is correct |
43 |
Correct |
3 ms |
1644 KB |
Output is correct |
44 |
Correct |
2 ms |
1644 KB |
Output is correct |
45 |
Correct |
2 ms |
1644 KB |
Output is correct |
46 |
Correct |
3 ms |
1644 KB |
Output is correct |
47 |
Correct |
2 ms |
1644 KB |
Output is correct |
48 |
Correct |
2 ms |
1644 KB |
Output is correct |
49 |
Correct |
2 ms |
1644 KB |
Output is correct |
50 |
Correct |
2 ms |
1644 KB |
Output is correct |
51 |
Correct |
2 ms |
1644 KB |
Output is correct |
52 |
Correct |
2 ms |
1644 KB |
Output is correct |
53 |
Correct |
2 ms |
1644 KB |
Output is correct |
54 |
Correct |
2 ms |
1772 KB |
Output is correct |
55 |
Correct |
2 ms |
1644 KB |
Output is correct |
56 |
Correct |
2 ms |
1644 KB |
Output is correct |
57 |
Correct |
2 ms |
1772 KB |
Output is correct |
58 |
Correct |
2 ms |
1644 KB |
Output is correct |
59 |
Correct |
2 ms |
1644 KB |
Output is correct |
60 |
Correct |
2 ms |
1644 KB |
Output is correct |
61 |
Correct |
2 ms |
1644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
0 ms |
364 KB |
Output is correct |
10 |
Correct |
0 ms |
364 KB |
Output is correct |
11 |
Correct |
0 ms |
364 KB |
Output is correct |
12 |
Correct |
0 ms |
364 KB |
Output is correct |
13 |
Correct |
0 ms |
364 KB |
Output is correct |
14 |
Correct |
0 ms |
364 KB |
Output is correct |
15 |
Correct |
0 ms |
364 KB |
Output is correct |
16 |
Correct |
0 ms |
364 KB |
Output is correct |
17 |
Correct |
0 ms |
492 KB |
Output is correct |
18 |
Correct |
0 ms |
492 KB |
Output is correct |
19 |
Correct |
1 ms |
492 KB |
Output is correct |
20 |
Correct |
1 ms |
492 KB |
Output is correct |
21 |
Correct |
1 ms |
492 KB |
Output is correct |
22 |
Correct |
1 ms |
492 KB |
Output is correct |
23 |
Correct |
1 ms |
492 KB |
Output is correct |
24 |
Correct |
1 ms |
492 KB |
Output is correct |
25 |
Correct |
1 ms |
492 KB |
Output is correct |
26 |
Correct |
0 ms |
492 KB |
Output is correct |
27 |
Correct |
0 ms |
492 KB |
Output is correct |
28 |
Correct |
1 ms |
492 KB |
Output is correct |
29 |
Correct |
0 ms |
492 KB |
Output is correct |
30 |
Correct |
1 ms |
492 KB |
Output is correct |
31 |
Correct |
0 ms |
492 KB |
Output is correct |
32 |
Correct |
0 ms |
492 KB |
Output is correct |
33 |
Correct |
0 ms |
492 KB |
Output is correct |
34 |
Correct |
1 ms |
492 KB |
Output is correct |
35 |
Correct |
1 ms |
492 KB |
Output is correct |
36 |
Correct |
0 ms |
492 KB |
Output is correct |
37 |
Correct |
1 ms |
492 KB |
Output is correct |
38 |
Correct |
0 ms |
492 KB |
Output is correct |
39 |
Correct |
1 ms |
1260 KB |
Output is correct |
40 |
Correct |
2 ms |
1644 KB |
Output is correct |
41 |
Correct |
2 ms |
1664 KB |
Output is correct |
42 |
Correct |
2 ms |
1644 KB |
Output is correct |
43 |
Correct |
3 ms |
1644 KB |
Output is correct |
44 |
Correct |
2 ms |
1644 KB |
Output is correct |
45 |
Correct |
2 ms |
1644 KB |
Output is correct |
46 |
Correct |
3 ms |
1644 KB |
Output is correct |
47 |
Correct |
2 ms |
1644 KB |
Output is correct |
48 |
Correct |
2 ms |
1644 KB |
Output is correct |
49 |
Correct |
2 ms |
1644 KB |
Output is correct |
50 |
Correct |
2 ms |
1644 KB |
Output is correct |
51 |
Correct |
2 ms |
1644 KB |
Output is correct |
52 |
Correct |
2 ms |
1644 KB |
Output is correct |
53 |
Correct |
2 ms |
1644 KB |
Output is correct |
54 |
Correct |
2 ms |
1772 KB |
Output is correct |
55 |
Correct |
2 ms |
1644 KB |
Output is correct |
56 |
Correct |
2 ms |
1644 KB |
Output is correct |
57 |
Correct |
2 ms |
1772 KB |
Output is correct |
58 |
Correct |
2 ms |
1644 KB |
Output is correct |
59 |
Correct |
2 ms |
1644 KB |
Output is correct |
60 |
Correct |
2 ms |
1644 KB |
Output is correct |
61 |
Correct |
2 ms |
1644 KB |
Output is correct |
62 |
Correct |
13 ms |
6252 KB |
Output is correct |
63 |
Correct |
49 ms |
14208 KB |
Output is correct |
64 |
Correct |
49 ms |
14188 KB |
Output is correct |
65 |
Correct |
49 ms |
14188 KB |
Output is correct |
66 |
Correct |
48 ms |
14188 KB |
Output is correct |
67 |
Correct |
49 ms |
14188 KB |
Output is correct |
68 |
Correct |
49 ms |
14124 KB |
Output is correct |
69 |
Correct |
49 ms |
14188 KB |
Output is correct |
70 |
Correct |
41 ms |
14188 KB |
Output is correct |
71 |
Correct |
40 ms |
14188 KB |
Output is correct |
72 |
Correct |
43 ms |
14188 KB |
Output is correct |
73 |
Correct |
40 ms |
14188 KB |
Output is correct |
74 |
Correct |
40 ms |
14188 KB |
Output is correct |
75 |
Correct |
40 ms |
14188 KB |
Output is correct |
76 |
Correct |
45 ms |
14188 KB |
Output is correct |
77 |
Correct |
37 ms |
14188 KB |
Output is correct |
78 |
Correct |
37 ms |
14188 KB |
Output is correct |
79 |
Correct |
36 ms |
14188 KB |
Output is correct |
80 |
Correct |
37 ms |
14188 KB |
Output is correct |
81 |
Correct |
36 ms |
14188 KB |
Output is correct |
82 |
Correct |
37 ms |
14188 KB |
Output is correct |
83 |
Correct |
48 ms |
14188 KB |
Output is correct |
84 |
Correct |
47 ms |
14188 KB |
Output is correct |
85 |
Correct |
41 ms |
14188 KB |
Output is correct |
86 |
Correct |
46 ms |
14316 KB |
Output is correct |