#include "mountains.h"
#include <vector>
const int NMAX = 2000;
int N;
int X[NMAX + 5], Y[NMAX + 5];
int dp[NMAX + 5][NMAX + 5];
struct Point {
int x, y;
};
struct Hull {
std::vector < Point > st;
void Clear() {
st.clear();
}
bool ccw(Point a, Point b, Point c) {
return ((1LL * a.x * (b.y - c.y) + 1LL * b.x * (c.y - a.y) + 1LL * c.x * (a.y - b.y)) <= 0);
}
void Push(Point p) {
while(st.size() > 1 && ccw(st[(int)st.size() - 1], st[(int)st.size() - 2], p)) {
st.pop_back();
}
st.push_back(p);
}
int Top() {
return st.back().x;
}
int Second() {
return st[(int)st.size() - 2].x;
}
};
int maximum_deevs(std::vector<int> y) {
N = (int)y.size();
for(int i = 0; i < N; i++) {
X[i + 1] = i + 1;
Y[i + 1] = y[i];
}
int res = 0;
for(int i = N; i >= 1; i--) {
Hull hull;
//hull.Clear();
for(int j = i; j <= N; j++) {
hull.Push({X[j], Y[j]});
int top = hull.Top();
dp[i][j] = 1;
dp[i][j] = std::max(dp[i][j], dp[i][top - 1] + dp[top + 1][j]);
if((int)hull.st.size() > 1) {
int second = hull.Second();
dp[i][j] = std::max(dp[i][j], dp[i][second - 1] + dp[second + 1][j]);
}
res = std::max(res, dp[i][j]);
}
}
return res;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
0 ms |
364 KB |
Output is correct |
8 |
Correct |
0 ms |
364 KB |
Output is correct |
9 |
Correct |
0 ms |
364 KB |
Output is correct |
10 |
Correct |
1 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 |
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
0 ms |
364 KB |
Output is correct |
8 |
Correct |
0 ms |
364 KB |
Output is correct |
9 |
Correct |
0 ms |
364 KB |
Output is correct |
10 |
Correct |
1 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 |
1 ms |
492 KB |
Output is correct |
18 |
Correct |
1 ms |
492 KB |
Output is correct |
19 |
Correct |
0 ms |
492 KB |
Output is correct |
20 |
Correct |
0 ms |
492 KB |
Output is correct |
21 |
Correct |
0 ms |
492 KB |
Output is correct |
22 |
Correct |
1 ms |
492 KB |
Output is correct |
23 |
Correct |
0 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 |
1 ms |
492 KB |
Output is correct |
27 |
Correct |
1 ms |
492 KB |
Output is correct |
28 |
Correct |
1 ms |
492 KB |
Output is correct |
29 |
Correct |
1 ms |
492 KB |
Output is correct |
30 |
Correct |
1 ms |
492 KB |
Output is correct |
31 |
Correct |
1 ms |
492 KB |
Output is correct |
32 |
Correct |
1 ms |
492 KB |
Output is correct |
33 |
Correct |
1 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 |
1 ms |
492 KB |
Output is correct |
37 |
Correct |
1 ms |
492 KB |
Output is correct |
38 |
Correct |
1 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
0 ms |
364 KB |
Output is correct |
8 |
Correct |
0 ms |
364 KB |
Output is correct |
9 |
Correct |
0 ms |
364 KB |
Output is correct |
10 |
Correct |
1 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 |
1 ms |
492 KB |
Output is correct |
18 |
Correct |
1 ms |
492 KB |
Output is correct |
19 |
Correct |
0 ms |
492 KB |
Output is correct |
20 |
Correct |
0 ms |
492 KB |
Output is correct |
21 |
Correct |
0 ms |
492 KB |
Output is correct |
22 |
Correct |
1 ms |
492 KB |
Output is correct |
23 |
Correct |
0 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 |
1 ms |
492 KB |
Output is correct |
27 |
Correct |
1 ms |
492 KB |
Output is correct |
28 |
Correct |
1 ms |
492 KB |
Output is correct |
29 |
Correct |
1 ms |
492 KB |
Output is correct |
30 |
Correct |
1 ms |
492 KB |
Output is correct |
31 |
Correct |
1 ms |
492 KB |
Output is correct |
32 |
Correct |
1 ms |
492 KB |
Output is correct |
33 |
Correct |
1 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 |
1 ms |
492 KB |
Output is correct |
37 |
Correct |
1 ms |
492 KB |
Output is correct |
38 |
Correct |
1 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 |
1644 KB |
Output is correct |
42 |
Correct |
2 ms |
1644 KB |
Output is correct |
43 |
Correct |
2 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 |
2 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 |
1644 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 |
1644 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 |
1772 KB |
Output is correct |
61 |
Correct |
2 ms |
1772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
0 ms |
364 KB |
Output is correct |
8 |
Correct |
0 ms |
364 KB |
Output is correct |
9 |
Correct |
0 ms |
364 KB |
Output is correct |
10 |
Correct |
1 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 |
1 ms |
492 KB |
Output is correct |
18 |
Correct |
1 ms |
492 KB |
Output is correct |
19 |
Correct |
0 ms |
492 KB |
Output is correct |
20 |
Correct |
0 ms |
492 KB |
Output is correct |
21 |
Correct |
0 ms |
492 KB |
Output is correct |
22 |
Correct |
1 ms |
492 KB |
Output is correct |
23 |
Correct |
0 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 |
1 ms |
492 KB |
Output is correct |
27 |
Correct |
1 ms |
492 KB |
Output is correct |
28 |
Correct |
1 ms |
492 KB |
Output is correct |
29 |
Correct |
1 ms |
492 KB |
Output is correct |
30 |
Correct |
1 ms |
492 KB |
Output is correct |
31 |
Correct |
1 ms |
492 KB |
Output is correct |
32 |
Correct |
1 ms |
492 KB |
Output is correct |
33 |
Correct |
1 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 |
1 ms |
492 KB |
Output is correct |
37 |
Correct |
1 ms |
492 KB |
Output is correct |
38 |
Correct |
1 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 |
1644 KB |
Output is correct |
42 |
Correct |
2 ms |
1644 KB |
Output is correct |
43 |
Correct |
2 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 |
2 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 |
1644 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 |
1644 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 |
1772 KB |
Output is correct |
61 |
Correct |
2 ms |
1772 KB |
Output is correct |
62 |
Correct |
13 ms |
6252 KB |
Output is correct |
63 |
Correct |
49 ms |
14188 KB |
Output is correct |
64 |
Correct |
50 ms |
14188 KB |
Output is correct |
65 |
Correct |
51 ms |
14188 KB |
Output is correct |
66 |
Correct |
49 ms |
14188 KB |
Output is correct |
67 |
Correct |
49 ms |
14188 KB |
Output is correct |
68 |
Correct |
49 ms |
14188 KB |
Output is correct |
69 |
Correct |
49 ms |
14188 KB |
Output is correct |
70 |
Correct |
43 ms |
14188 KB |
Output is correct |
71 |
Correct |
42 ms |
14188 KB |
Output is correct |
72 |
Correct |
43 ms |
14188 KB |
Output is correct |
73 |
Correct |
42 ms |
14188 KB |
Output is correct |
74 |
Correct |
42 ms |
14188 KB |
Output is correct |
75 |
Correct |
42 ms |
14188 KB |
Output is correct |
76 |
Correct |
47 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 |
40 ms |
14188 KB |
Output is correct |
80 |
Correct |
37 ms |
14188 KB |
Output is correct |
81 |
Correct |
37 ms |
14188 KB |
Output is correct |
82 |
Correct |
41 ms |
14336 KB |
Output is correct |
83 |
Correct |
49 ms |
14188 KB |
Output is correct |
84 |
Correct |
49 ms |
14188 KB |
Output is correct |
85 |
Correct |
47 ms |
14188 KB |
Output is correct |
86 |
Correct |
47 ms |
14188 KB |
Output is correct |