Submission #340700

# Submission time Handle Problem Language Result Execution time Memory
340700 2020-12-28T08:24:42 Z mihai145 Mountains (IOI17_mountains) C++14
100 / 100
55 ms 14316 KB
#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 <long long, long long> st[NMAX + 5];

bool ccw(std::pair <long long, long long> a, std::pair <long long, long long> b, std::pair <long long, long long> 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();
    int ret = 0;

    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]);
            }

            ret = std::max(ret, dp[i][j]);
        }
    }

	return ret;
}
# Verdict Execution time Memory Grader output
1 Correct 1 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 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 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 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 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 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 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 1 ms 364 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
# Verdict Execution time Memory Grader output
1 Correct 1 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 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 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 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 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 1 ms 364 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 3 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 3 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 3 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 3 ms 1644 KB Output is correct
55 Correct 2 ms 1644 KB Output is correct
56 Correct 3 ms 1644 KB Output is correct
57 Correct 2 ms 1644 KB Output is correct
58 Correct 3 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
# Verdict Execution time Memory Grader output
1 Correct 1 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 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 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 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 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 1 ms 364 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 3 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 3 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 3 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 3 ms 1644 KB Output is correct
55 Correct 2 ms 1644 KB Output is correct
56 Correct 3 ms 1644 KB Output is correct
57 Correct 2 ms 1644 KB Output is correct
58 Correct 3 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 53 ms 14188 KB Output is correct
64 Correct 54 ms 14188 KB Output is correct
65 Correct 55 ms 14188 KB Output is correct
66 Correct 50 ms 14188 KB Output is correct
67 Correct 50 ms 14188 KB Output is correct
68 Correct 50 ms 14208 KB Output is correct
69 Correct 50 ms 14188 KB Output is correct
70 Correct 41 ms 14188 KB Output is correct
71 Correct 41 ms 14188 KB Output is correct
72 Correct 41 ms 14188 KB Output is correct
73 Correct 41 ms 14316 KB Output is correct
74 Correct 41 ms 14188 KB Output is correct
75 Correct 41 ms 14188 KB Output is correct
76 Correct 45 ms 14188 KB Output is correct
77 Correct 39 ms 14188 KB Output is correct
78 Correct 39 ms 14188 KB Output is correct
79 Correct 41 ms 14188 KB Output is correct
80 Correct 38 ms 14188 KB Output is correct
81 Correct 39 ms 14188 KB Output is correct
82 Correct 38 ms 14188 KB Output is correct
83 Correct 49 ms 14188 KB Output is correct
84 Correct 48 ms 14188 KB Output is correct
85 Correct 41 ms 14188 KB Output is correct
86 Correct 42 ms 14188 KB Output is correct