#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 * (B.y - A.y) * (C.x - A.x) <= 1LL * (C.y - A.y) * (B.x - A.x);
}
void Push(std::pair <int, int> dot) {
while(vf > 1 && ccw(st[vf - 1], st[vf], 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 |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
1 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 |
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 |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
0 ms |
364 KB |
Output is correct |
15 |
Correct |
1 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 |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
1 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 |
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 |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
0 ms |
364 KB |
Output is correct |
15 |
Correct |
1 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 |
1 ms |
492 KB |
Output is correct |
20 |
Correct |
1 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 |
1 ms |
492 KB |
Output is correct |
24 |
Correct |
0 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 |
0 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 |
0 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 |
0 ms |
492 KB |
Output is correct |
37 |
Correct |
1 ms |
492 KB |
Output is correct |
38 |
Correct |
1 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 |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
1 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 |
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 |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
0 ms |
364 KB |
Output is correct |
15 |
Correct |
1 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 |
1 ms |
492 KB |
Output is correct |
20 |
Correct |
1 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 |
1 ms |
492 KB |
Output is correct |
24 |
Correct |
0 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 |
0 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 |
0 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 |
0 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 |
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 |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
1 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 |
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 |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
0 ms |
364 KB |
Output is correct |
15 |
Correct |
1 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 |
1 ms |
492 KB |
Output is correct |
20 |
Correct |
1 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 |
1 ms |
492 KB |
Output is correct |
24 |
Correct |
0 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 |
0 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 |
0 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 |
0 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 |
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 |
50 ms |
14188 KB |
Output is correct |
64 |
Correct |
49 ms |
14188 KB |
Output is correct |
65 |
Correct |
49 ms |
14188 KB |
Output is correct |
66 |
Correct |
51 ms |
14188 KB |
Output is correct |
67 |
Correct |
49 ms |
14188 KB |
Output is correct |
68 |
Correct |
50 ms |
14188 KB |
Output is correct |
69 |
Correct |
50 ms |
14160 KB |
Output is correct |
70 |
Correct |
41 ms |
14188 KB |
Output is correct |
71 |
Correct |
40 ms |
14188 KB |
Output is correct |
72 |
Correct |
44 ms |
14188 KB |
Output is correct |
73 |
Correct |
39 ms |
14188 KB |
Output is correct |
74 |
Correct |
40 ms |
14188 KB |
Output is correct |
75 |
Correct |
41 ms |
14188 KB |
Output is correct |
76 |
Correct |
46 ms |
14188 KB |
Output is correct |
77 |
Correct |
39 ms |
14188 KB |
Output is correct |
78 |
Correct |
36 ms |
14188 KB |
Output is correct |
79 |
Correct |
36 ms |
14200 KB |
Output is correct |
80 |
Correct |
39 ms |
14188 KB |
Output is correct |
81 |
Correct |
37 ms |
14188 KB |
Output is correct |
82 |
Correct |
35 ms |
14188 KB |
Output is correct |
83 |
Correct |
47 ms |
14188 KB |
Output is correct |
84 |
Correct |
51 ms |
14188 KB |
Output is correct |
85 |
Correct |
39 ms |
14188 KB |
Output is correct |
86 |
Correct |
39 ms |
14188 KB |
Output is correct |