#include <bits/stdc++.h>
using namespace std;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif
int maximum_deevs(vector<int> y) {
int n = (int) y.size();
vector<vector<int>> dp(n + 1, vector<int>(n + 1));
function<int(int, int)> solve = [&](int l, int r) {
if (l >= r) {
return 0;
}
if (dp[l][r]) {
return dp[l][r];
}
int pos = (int) (max_element(y.begin() + l, y.begin() + r) - y.begin());
dp[l][r] = 1;
int lst = pos;
pair<int, int> a = make_pair(1, 0);
for (int i = pos - 1; i >= l; i--) {
auto b = make_pair(y[pos] - y[i], pos - i);
if (1LL * a.first * b.second >= 1LL * a.second * b.first) {
a = b;
dp[l][r] += solve(i + 1, lst);
lst = i;
}
}
dp[l][r] += solve(l, lst);
lst = pos;
a = make_pair(1, 0);
for (int i = pos + 1; i < r; i++) {
auto b = make_pair(y[pos] - y[i], i - pos);
if (1LL * a.first * b.second >= 1LL * a.second * b.first) {
a = b;
dp[l][r] += solve(lst + 1, i);
lst = i;
}
}
dp[l][r] += solve(lst + 1, r);
dp[l][r] = max(dp[l][r], solve(l, pos) + solve(pos + 1, r));
return dp[l][r];
};
return solve(0, n);
}
#ifdef tabr
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
debug(maximum_deevs({6, 1, 5, 2, 3, 1}));
debug(maximum_deevs({0, 1, 2}));
return 0;
}
#endif
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
0 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
0 ms |
204 KB |
Output is correct |
26 |
Correct |
0 ms |
204 KB |
Output is correct |
27 |
Correct |
1 ms |
204 KB |
Output is correct |
28 |
Correct |
1 ms |
204 KB |
Output is correct |
29 |
Correct |
0 ms |
204 KB |
Output is correct |
30 |
Correct |
1 ms |
204 KB |
Output is correct |
31 |
Correct |
1 ms |
204 KB |
Output is correct |
32 |
Correct |
1 ms |
204 KB |
Output is correct |
33 |
Correct |
0 ms |
204 KB |
Output is correct |
34 |
Correct |
0 ms |
204 KB |
Output is correct |
35 |
Correct |
0 ms |
204 KB |
Output is correct |
36 |
Correct |
1 ms |
204 KB |
Output is correct |
37 |
Correct |
0 ms |
204 KB |
Output is correct |
38 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
0 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
0 ms |
204 KB |
Output is correct |
26 |
Correct |
0 ms |
204 KB |
Output is correct |
27 |
Correct |
1 ms |
204 KB |
Output is correct |
28 |
Correct |
1 ms |
204 KB |
Output is correct |
29 |
Correct |
0 ms |
204 KB |
Output is correct |
30 |
Correct |
1 ms |
204 KB |
Output is correct |
31 |
Correct |
1 ms |
204 KB |
Output is correct |
32 |
Correct |
1 ms |
204 KB |
Output is correct |
33 |
Correct |
0 ms |
204 KB |
Output is correct |
34 |
Correct |
0 ms |
204 KB |
Output is correct |
35 |
Correct |
0 ms |
204 KB |
Output is correct |
36 |
Correct |
1 ms |
204 KB |
Output is correct |
37 |
Correct |
0 ms |
204 KB |
Output is correct |
38 |
Correct |
0 ms |
204 KB |
Output is correct |
39 |
Correct |
1 ms |
332 KB |
Output is correct |
40 |
Correct |
1 ms |
588 KB |
Output is correct |
41 |
Correct |
1 ms |
588 KB |
Output is correct |
42 |
Correct |
1 ms |
588 KB |
Output is correct |
43 |
Correct |
1 ms |
588 KB |
Output is correct |
44 |
Correct |
1 ms |
588 KB |
Output is correct |
45 |
Correct |
1 ms |
588 KB |
Output is correct |
46 |
Correct |
1 ms |
588 KB |
Output is correct |
47 |
Correct |
1 ms |
588 KB |
Output is correct |
48 |
Correct |
1 ms |
588 KB |
Output is correct |
49 |
Correct |
1 ms |
588 KB |
Output is correct |
50 |
Correct |
1 ms |
588 KB |
Output is correct |
51 |
Correct |
1 ms |
588 KB |
Output is correct |
52 |
Correct |
4 ms |
588 KB |
Output is correct |
53 |
Correct |
2 ms |
676 KB |
Output is correct |
54 |
Correct |
3 ms |
588 KB |
Output is correct |
55 |
Correct |
3 ms |
588 KB |
Output is correct |
56 |
Correct |
3 ms |
588 KB |
Output is correct |
57 |
Correct |
1 ms |
588 KB |
Output is correct |
58 |
Correct |
1 ms |
588 KB |
Output is correct |
59 |
Correct |
1 ms |
588 KB |
Output is correct |
60 |
Correct |
1 ms |
588 KB |
Output is correct |
61 |
Correct |
1 ms |
588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
0 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
0 ms |
204 KB |
Output is correct |
26 |
Correct |
0 ms |
204 KB |
Output is correct |
27 |
Correct |
1 ms |
204 KB |
Output is correct |
28 |
Correct |
1 ms |
204 KB |
Output is correct |
29 |
Correct |
0 ms |
204 KB |
Output is correct |
30 |
Correct |
1 ms |
204 KB |
Output is correct |
31 |
Correct |
1 ms |
204 KB |
Output is correct |
32 |
Correct |
1 ms |
204 KB |
Output is correct |
33 |
Correct |
0 ms |
204 KB |
Output is correct |
34 |
Correct |
0 ms |
204 KB |
Output is correct |
35 |
Correct |
0 ms |
204 KB |
Output is correct |
36 |
Correct |
1 ms |
204 KB |
Output is correct |
37 |
Correct |
0 ms |
204 KB |
Output is correct |
38 |
Correct |
0 ms |
204 KB |
Output is correct |
39 |
Correct |
1 ms |
332 KB |
Output is correct |
40 |
Correct |
1 ms |
588 KB |
Output is correct |
41 |
Correct |
1 ms |
588 KB |
Output is correct |
42 |
Correct |
1 ms |
588 KB |
Output is correct |
43 |
Correct |
1 ms |
588 KB |
Output is correct |
44 |
Correct |
1 ms |
588 KB |
Output is correct |
45 |
Correct |
1 ms |
588 KB |
Output is correct |
46 |
Correct |
1 ms |
588 KB |
Output is correct |
47 |
Correct |
1 ms |
588 KB |
Output is correct |
48 |
Correct |
1 ms |
588 KB |
Output is correct |
49 |
Correct |
1 ms |
588 KB |
Output is correct |
50 |
Correct |
1 ms |
588 KB |
Output is correct |
51 |
Correct |
1 ms |
588 KB |
Output is correct |
52 |
Correct |
4 ms |
588 KB |
Output is correct |
53 |
Correct |
2 ms |
676 KB |
Output is correct |
54 |
Correct |
3 ms |
588 KB |
Output is correct |
55 |
Correct |
3 ms |
588 KB |
Output is correct |
56 |
Correct |
3 ms |
588 KB |
Output is correct |
57 |
Correct |
1 ms |
588 KB |
Output is correct |
58 |
Correct |
1 ms |
588 KB |
Output is correct |
59 |
Correct |
1 ms |
588 KB |
Output is correct |
60 |
Correct |
1 ms |
588 KB |
Output is correct |
61 |
Correct |
1 ms |
588 KB |
Output is correct |
62 |
Correct |
2 ms |
4172 KB |
Output is correct |
63 |
Correct |
7 ms |
16032 KB |
Output is correct |
64 |
Correct |
8 ms |
16044 KB |
Output is correct |
65 |
Correct |
8 ms |
16044 KB |
Output is correct |
66 |
Correct |
7 ms |
16056 KB |
Output is correct |
67 |
Correct |
8 ms |
16004 KB |
Output is correct |
68 |
Correct |
8 ms |
16076 KB |
Output is correct |
69 |
Correct |
9 ms |
16076 KB |
Output is correct |
70 |
Correct |
16 ms |
16140 KB |
Output is correct |
71 |
Correct |
16 ms |
16236 KB |
Output is correct |
72 |
Correct |
17 ms |
16228 KB |
Output is correct |
73 |
Correct |
16 ms |
16172 KB |
Output is correct |
74 |
Correct |
17 ms |
16176 KB |
Output is correct |
75 |
Correct |
17 ms |
16204 KB |
Output is correct |
76 |
Correct |
10 ms |
15960 KB |
Output is correct |
77 |
Correct |
43 ms |
16192 KB |
Output is correct |
78 |
Correct |
40 ms |
16232 KB |
Output is correct |
79 |
Correct |
45 ms |
16196 KB |
Output is correct |
80 |
Correct |
42 ms |
16144 KB |
Output is correct |
81 |
Correct |
41 ms |
16196 KB |
Output is correct |
82 |
Correct |
14 ms |
16172 KB |
Output is correct |
83 |
Correct |
17 ms |
16076 KB |
Output is correct |
84 |
Correct |
16 ms |
16068 KB |
Output is correct |
85 |
Correct |
14 ms |
16256 KB |
Output is correct |
86 |
Correct |
15 ms |
16204 KB |
Output is correct |