#include "mountains.h"
#include <vector>
#define MAXN 2005
using namespace std;
int N, dp[MAXN][MAXN];
long long H[MAXN];
bool block(int i, int j, int k) {
//does j block view of i to k (i<=j<=k)?
if (j == k || j == i) {return(false);}
return((H[k]-H[j])*(k-i) < (H[k]-H[i])*(k-j));
}
int slv(int l, int r) {
if (l >= r) {return(max(r-l+1,0));}
if (dp[l][r]) {return(dp[l][r]);}
int peak=0, lh, rh, val=1;
for (int i=l; i<=r; i++) {
if (H[i] >= H[peak]) {
peak=i;
}
}
dp[l][r]=slv(l, peak-1) + slv(peak+1,r); //ignore cur
lh = peak, rh = peak;
for (int i=peak-1; i>=l; i--) {
if (block(i, lh, peak)) {continue;}
else {
val += slv(i+1, lh-1);
lh = i;
}
}
for (int i=peak+1; i<=r; i++) {
if (block(peak, rh, i)) {continue;}
else {
val += slv(rh+1, i-1);
rh = i;
}
}
val+=slv(l, lh-1) + slv(rh+1, r);
dp[l][r]=max(dp[l][r], val);
return(dp[l][r]);
}
int maximum_deevs(vector<int> y) {
N=y.size();
for (int i=1; i<=N; i++) {
H[i] = y[i-1];
}
return(slv(1,N));
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
4 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
4 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
6 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
380 KB |
Output is correct |
9 |
Correct |
5 ms |
380 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
4 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
4 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
6 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
380 KB |
Output is correct |
9 |
Correct |
5 ms |
380 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
5 ms |
380 KB |
Output is correct |
20 |
Correct |
5 ms |
376 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
22 |
Correct |
4 ms |
376 KB |
Output is correct |
23 |
Correct |
5 ms |
376 KB |
Output is correct |
24 |
Correct |
5 ms |
376 KB |
Output is correct |
25 |
Correct |
5 ms |
376 KB |
Output is correct |
26 |
Correct |
5 ms |
380 KB |
Output is correct |
27 |
Correct |
5 ms |
376 KB |
Output is correct |
28 |
Correct |
5 ms |
376 KB |
Output is correct |
29 |
Correct |
5 ms |
376 KB |
Output is correct |
30 |
Correct |
5 ms |
376 KB |
Output is correct |
31 |
Correct |
5 ms |
376 KB |
Output is correct |
32 |
Correct |
5 ms |
376 KB |
Output is correct |
33 |
Correct |
5 ms |
256 KB |
Output is correct |
34 |
Correct |
5 ms |
376 KB |
Output is correct |
35 |
Correct |
5 ms |
256 KB |
Output is correct |
36 |
Correct |
4 ms |
256 KB |
Output is correct |
37 |
Correct |
5 ms |
376 KB |
Output is correct |
38 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
4 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
4 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
6 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
380 KB |
Output is correct |
9 |
Correct |
5 ms |
380 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
5 ms |
380 KB |
Output is correct |
20 |
Correct |
5 ms |
376 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
22 |
Correct |
4 ms |
376 KB |
Output is correct |
23 |
Correct |
5 ms |
376 KB |
Output is correct |
24 |
Correct |
5 ms |
376 KB |
Output is correct |
25 |
Correct |
5 ms |
376 KB |
Output is correct |
26 |
Correct |
5 ms |
380 KB |
Output is correct |
27 |
Correct |
5 ms |
376 KB |
Output is correct |
28 |
Correct |
5 ms |
376 KB |
Output is correct |
29 |
Correct |
5 ms |
376 KB |
Output is correct |
30 |
Correct |
5 ms |
376 KB |
Output is correct |
31 |
Correct |
5 ms |
376 KB |
Output is correct |
32 |
Correct |
5 ms |
376 KB |
Output is correct |
33 |
Correct |
5 ms |
256 KB |
Output is correct |
34 |
Correct |
5 ms |
376 KB |
Output is correct |
35 |
Correct |
5 ms |
256 KB |
Output is correct |
36 |
Correct |
4 ms |
256 KB |
Output is correct |
37 |
Correct |
5 ms |
376 KB |
Output is correct |
38 |
Correct |
5 ms |
376 KB |
Output is correct |
39 |
Correct |
5 ms |
632 KB |
Output is correct |
40 |
Correct |
5 ms |
816 KB |
Output is correct |
41 |
Correct |
5 ms |
760 KB |
Output is correct |
42 |
Correct |
5 ms |
632 KB |
Output is correct |
43 |
Correct |
5 ms |
760 KB |
Output is correct |
44 |
Correct |
5 ms |
760 KB |
Output is correct |
45 |
Correct |
5 ms |
760 KB |
Output is correct |
46 |
Correct |
5 ms |
764 KB |
Output is correct |
47 |
Correct |
5 ms |
760 KB |
Output is correct |
48 |
Correct |
5 ms |
632 KB |
Output is correct |
49 |
Correct |
5 ms |
888 KB |
Output is correct |
50 |
Correct |
5 ms |
888 KB |
Output is correct |
51 |
Correct |
5 ms |
504 KB |
Output is correct |
52 |
Correct |
8 ms |
1016 KB |
Output is correct |
53 |
Correct |
7 ms |
1016 KB |
Output is correct |
54 |
Correct |
8 ms |
1016 KB |
Output is correct |
55 |
Correct |
7 ms |
1016 KB |
Output is correct |
56 |
Correct |
8 ms |
1020 KB |
Output is correct |
57 |
Correct |
5 ms |
376 KB |
Output is correct |
58 |
Correct |
6 ms |
632 KB |
Output is correct |
59 |
Correct |
5 ms |
632 KB |
Output is correct |
60 |
Correct |
5 ms |
376 KB |
Output is correct |
61 |
Correct |
6 ms |
1504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
4 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
4 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
6 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
380 KB |
Output is correct |
9 |
Correct |
5 ms |
380 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
5 ms |
380 KB |
Output is correct |
20 |
Correct |
5 ms |
376 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
22 |
Correct |
4 ms |
376 KB |
Output is correct |
23 |
Correct |
5 ms |
376 KB |
Output is correct |
24 |
Correct |
5 ms |
376 KB |
Output is correct |
25 |
Correct |
5 ms |
376 KB |
Output is correct |
26 |
Correct |
5 ms |
380 KB |
Output is correct |
27 |
Correct |
5 ms |
376 KB |
Output is correct |
28 |
Correct |
5 ms |
376 KB |
Output is correct |
29 |
Correct |
5 ms |
376 KB |
Output is correct |
30 |
Correct |
5 ms |
376 KB |
Output is correct |
31 |
Correct |
5 ms |
376 KB |
Output is correct |
32 |
Correct |
5 ms |
376 KB |
Output is correct |
33 |
Correct |
5 ms |
256 KB |
Output is correct |
34 |
Correct |
5 ms |
376 KB |
Output is correct |
35 |
Correct |
5 ms |
256 KB |
Output is correct |
36 |
Correct |
4 ms |
256 KB |
Output is correct |
37 |
Correct |
5 ms |
376 KB |
Output is correct |
38 |
Correct |
5 ms |
376 KB |
Output is correct |
39 |
Correct |
5 ms |
632 KB |
Output is correct |
40 |
Correct |
5 ms |
816 KB |
Output is correct |
41 |
Correct |
5 ms |
760 KB |
Output is correct |
42 |
Correct |
5 ms |
632 KB |
Output is correct |
43 |
Correct |
5 ms |
760 KB |
Output is correct |
44 |
Correct |
5 ms |
760 KB |
Output is correct |
45 |
Correct |
5 ms |
760 KB |
Output is correct |
46 |
Correct |
5 ms |
764 KB |
Output is correct |
47 |
Correct |
5 ms |
760 KB |
Output is correct |
48 |
Correct |
5 ms |
632 KB |
Output is correct |
49 |
Correct |
5 ms |
888 KB |
Output is correct |
50 |
Correct |
5 ms |
888 KB |
Output is correct |
51 |
Correct |
5 ms |
504 KB |
Output is correct |
52 |
Correct |
8 ms |
1016 KB |
Output is correct |
53 |
Correct |
7 ms |
1016 KB |
Output is correct |
54 |
Correct |
8 ms |
1016 KB |
Output is correct |
55 |
Correct |
7 ms |
1016 KB |
Output is correct |
56 |
Correct |
8 ms |
1020 KB |
Output is correct |
57 |
Correct |
5 ms |
376 KB |
Output is correct |
58 |
Correct |
6 ms |
632 KB |
Output is correct |
59 |
Correct |
5 ms |
632 KB |
Output is correct |
60 |
Correct |
5 ms |
376 KB |
Output is correct |
61 |
Correct |
6 ms |
1504 KB |
Output is correct |
62 |
Correct |
6 ms |
1660 KB |
Output is correct |
63 |
Correct |
8 ms |
3068 KB |
Output is correct |
64 |
Correct |
7 ms |
3064 KB |
Output is correct |
65 |
Correct |
8 ms |
3064 KB |
Output is correct |
66 |
Correct |
7 ms |
3064 KB |
Output is correct |
67 |
Correct |
7 ms |
3192 KB |
Output is correct |
68 |
Correct |
7 ms |
3064 KB |
Output is correct |
69 |
Correct |
7 ms |
3064 KB |
Output is correct |
70 |
Correct |
18 ms |
4216 KB |
Output is correct |
71 |
Correct |
17 ms |
4216 KB |
Output is correct |
72 |
Correct |
17 ms |
4088 KB |
Output is correct |
73 |
Correct |
17 ms |
4344 KB |
Output is correct |
74 |
Correct |
17 ms |
4088 KB |
Output is correct |
75 |
Correct |
16 ms |
4216 KB |
Output is correct |
76 |
Correct |
7 ms |
1912 KB |
Output is correct |
77 |
Correct |
57 ms |
1528 KB |
Output is correct |
78 |
Correct |
50 ms |
1400 KB |
Output is correct |
79 |
Correct |
56 ms |
1528 KB |
Output is correct |
80 |
Correct |
54 ms |
1400 KB |
Output is correct |
81 |
Correct |
44 ms |
1400 KB |
Output is correct |
82 |
Correct |
20 ms |
504 KB |
Output is correct |
83 |
Correct |
48 ms |
2936 KB |
Output is correct |
84 |
Correct |
40 ms |
3064 KB |
Output is correct |
85 |
Correct |
18 ms |
504 KB |
Output is correct |
86 |
Correct |
23 ms |
8568 KB |
Output is correct |