Submission #74435

# Submission time Handle Problem Language Result Execution time Memory
74435 2018-09-01T09:55:32 Z mjt Mountains (IOI17_mountains) C++11
100 / 100
21 ms 9464 KB
#include"mountains.h"
#include<bits/stdc++.h>
using namespace std;

const int N = 2010;
int y[N];
int f[N][N];

bool Judge(int a,int b,int c) { // a see c ?
	// ((y[a] - y[b]) / (a - b)) > ((y[a] - y[c]) / (a - c));
	return 1ll * (y[a] - y[b]) * (a - c) > 1ll * (y[a] - y[c]) * (a - b);
}

int solve(int l,int r) {
	if (f[l][r]) return f[l][r];
	if (l > r) return 0;
	if (l == r) return 1;
	int pos = -1, mx = -1;
	for (int i=l; i<=r; ++i) if (y[i] > mx) pos = i, mx = y[i];
	int ans1 = solve(l, pos - 1) + solve(pos + 1, r);
	
	int ans2 = 0;
	for (int i=pos-1,j; i>=l; i=j) {
		for (j=i-1; j>=l; --j) {
			if (Judge(j, i, pos)) {
				if (j == l) ans2 += solve(l, i - 1);
				continue;
			}
			if (j + 1 <= i - 1) ans2 += solve(j + 1, i - 1);
			break;
		}
	}
	for (int i=pos+1,j; i<=r; i=j) {
		for (j=i+1; j<=r; ++j) {
			if (Judge(pos, i, j)) {
				if (j == r) ans2 += solve(i + 1, r);
				continue;
			}
			if (i + 1 <= j - 1) ans2 += solve(i + 1, j - 1);
			break;
		}
	} 
	return f[l][r] = max(ans1, ans2 + 1);
}

int maximum_deevs(vector<int> A) {
	int n = A.size();
	for (int i=1; i<=n; ++i) y[i] = A[i - 1];
	return solve(1, n);
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 372 KB Output is correct
3 Correct 2 ms 452 KB Output is correct
4 Correct 2 ms 592 KB Output is correct
5 Correct 2 ms 592 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 2 ms 592 KB Output is correct
8 Correct 2 ms 592 KB Output is correct
9 Correct 2 ms 592 KB Output is correct
10 Correct 2 ms 624 KB Output is correct
11 Correct 2 ms 648 KB Output is correct
12 Correct 2 ms 652 KB Output is correct
13 Correct 2 ms 728 KB Output is correct
14 Correct 2 ms 728 KB Output is correct
15 Correct 2 ms 728 KB Output is correct
16 Correct 2 ms 728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 372 KB Output is correct
3 Correct 2 ms 452 KB Output is correct
4 Correct 2 ms 592 KB Output is correct
5 Correct 2 ms 592 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 2 ms 592 KB Output is correct
8 Correct 2 ms 592 KB Output is correct
9 Correct 2 ms 592 KB Output is correct
10 Correct 2 ms 624 KB Output is correct
11 Correct 2 ms 648 KB Output is correct
12 Correct 2 ms 652 KB Output is correct
13 Correct 2 ms 728 KB Output is correct
14 Correct 2 ms 728 KB Output is correct
15 Correct 2 ms 728 KB Output is correct
16 Correct 2 ms 728 KB Output is correct
17 Correct 2 ms 728 KB Output is correct
18 Correct 2 ms 728 KB Output is correct
19 Correct 2 ms 728 KB Output is correct
20 Correct 2 ms 728 KB Output is correct
21 Correct 2 ms 728 KB Output is correct
22 Correct 2 ms 728 KB Output is correct
23 Correct 2 ms 728 KB Output is correct
24 Correct 2 ms 728 KB Output is correct
25 Correct 2 ms 728 KB Output is correct
26 Correct 2 ms 728 KB Output is correct
27 Correct 2 ms 728 KB Output is correct
28 Correct 2 ms 728 KB Output is correct
29 Correct 2 ms 728 KB Output is correct
30 Correct 3 ms 728 KB Output is correct
31 Correct 2 ms 736 KB Output is correct
32 Correct 2 ms 736 KB Output is correct
33 Correct 2 ms 740 KB Output is correct
34 Correct 2 ms 744 KB Output is correct
35 Correct 2 ms 748 KB Output is correct
36 Correct 2 ms 752 KB Output is correct
37 Correct 2 ms 884 KB Output is correct
38 Correct 2 ms 888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 372 KB Output is correct
3 Correct 2 ms 452 KB Output is correct
4 Correct 2 ms 592 KB Output is correct
5 Correct 2 ms 592 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 2 ms 592 KB Output is correct
8 Correct 2 ms 592 KB Output is correct
9 Correct 2 ms 592 KB Output is correct
10 Correct 2 ms 624 KB Output is correct
11 Correct 2 ms 648 KB Output is correct
12 Correct 2 ms 652 KB Output is correct
13 Correct 2 ms 728 KB Output is correct
14 Correct 2 ms 728 KB Output is correct
15 Correct 2 ms 728 KB Output is correct
16 Correct 2 ms 728 KB Output is correct
17 Correct 2 ms 728 KB Output is correct
18 Correct 2 ms 728 KB Output is correct
19 Correct 2 ms 728 KB Output is correct
20 Correct 2 ms 728 KB Output is correct
21 Correct 2 ms 728 KB Output is correct
22 Correct 2 ms 728 KB Output is correct
23 Correct 2 ms 728 KB Output is correct
24 Correct 2 ms 728 KB Output is correct
25 Correct 2 ms 728 KB Output is correct
26 Correct 2 ms 728 KB Output is correct
27 Correct 2 ms 728 KB Output is correct
28 Correct 2 ms 728 KB Output is correct
29 Correct 2 ms 728 KB Output is correct
30 Correct 3 ms 728 KB Output is correct
31 Correct 2 ms 736 KB Output is correct
32 Correct 2 ms 736 KB Output is correct
33 Correct 2 ms 740 KB Output is correct
34 Correct 2 ms 744 KB Output is correct
35 Correct 2 ms 748 KB Output is correct
36 Correct 2 ms 752 KB Output is correct
37 Correct 2 ms 884 KB Output is correct
38 Correct 2 ms 888 KB Output is correct
39 Correct 2 ms 1020 KB Output is correct
40 Correct 3 ms 1152 KB Output is correct
41 Correct 3 ms 1156 KB Output is correct
42 Correct 3 ms 1160 KB Output is correct
43 Correct 3 ms 1164 KB Output is correct
44 Correct 2 ms 1168 KB Output is correct
45 Correct 3 ms 1172 KB Output is correct
46 Correct 3 ms 1304 KB Output is correct
47 Correct 3 ms 1308 KB Output is correct
48 Correct 3 ms 1308 KB Output is correct
49 Correct 3 ms 1316 KB Output is correct
50 Correct 3 ms 1320 KB Output is correct
51 Correct 2 ms 1320 KB Output is correct
52 Correct 4 ms 1456 KB Output is correct
53 Correct 4 ms 1460 KB Output is correct
54 Correct 4 ms 1464 KB Output is correct
55 Correct 4 ms 1468 KB Output is correct
56 Correct 5 ms 1480 KB Output is correct
57 Correct 2 ms 1480 KB Output is correct
58 Correct 3 ms 1480 KB Output is correct
59 Correct 3 ms 1480 KB Output is correct
60 Correct 3 ms 1480 KB Output is correct
61 Correct 3 ms 2004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 372 KB Output is correct
3 Correct 2 ms 452 KB Output is correct
4 Correct 2 ms 592 KB Output is correct
5 Correct 2 ms 592 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 2 ms 592 KB Output is correct
8 Correct 2 ms 592 KB Output is correct
9 Correct 2 ms 592 KB Output is correct
10 Correct 2 ms 624 KB Output is correct
11 Correct 2 ms 648 KB Output is correct
12 Correct 2 ms 652 KB Output is correct
13 Correct 2 ms 728 KB Output is correct
14 Correct 2 ms 728 KB Output is correct
15 Correct 2 ms 728 KB Output is correct
16 Correct 2 ms 728 KB Output is correct
17 Correct 2 ms 728 KB Output is correct
18 Correct 2 ms 728 KB Output is correct
19 Correct 2 ms 728 KB Output is correct
20 Correct 2 ms 728 KB Output is correct
21 Correct 2 ms 728 KB Output is correct
22 Correct 2 ms 728 KB Output is correct
23 Correct 2 ms 728 KB Output is correct
24 Correct 2 ms 728 KB Output is correct
25 Correct 2 ms 728 KB Output is correct
26 Correct 2 ms 728 KB Output is correct
27 Correct 2 ms 728 KB Output is correct
28 Correct 2 ms 728 KB Output is correct
29 Correct 2 ms 728 KB Output is correct
30 Correct 3 ms 728 KB Output is correct
31 Correct 2 ms 736 KB Output is correct
32 Correct 2 ms 736 KB Output is correct
33 Correct 2 ms 740 KB Output is correct
34 Correct 2 ms 744 KB Output is correct
35 Correct 2 ms 748 KB Output is correct
36 Correct 2 ms 752 KB Output is correct
37 Correct 2 ms 884 KB Output is correct
38 Correct 2 ms 888 KB Output is correct
39 Correct 2 ms 1020 KB Output is correct
40 Correct 3 ms 1152 KB Output is correct
41 Correct 3 ms 1156 KB Output is correct
42 Correct 3 ms 1160 KB Output is correct
43 Correct 3 ms 1164 KB Output is correct
44 Correct 2 ms 1168 KB Output is correct
45 Correct 3 ms 1172 KB Output is correct
46 Correct 3 ms 1304 KB Output is correct
47 Correct 3 ms 1308 KB Output is correct
48 Correct 3 ms 1308 KB Output is correct
49 Correct 3 ms 1316 KB Output is correct
50 Correct 3 ms 1320 KB Output is correct
51 Correct 2 ms 1320 KB Output is correct
52 Correct 4 ms 1456 KB Output is correct
53 Correct 4 ms 1460 KB Output is correct
54 Correct 4 ms 1464 KB Output is correct
55 Correct 4 ms 1468 KB Output is correct
56 Correct 5 ms 1480 KB Output is correct
57 Correct 2 ms 1480 KB Output is correct
58 Correct 3 ms 1480 KB Output is correct
59 Correct 3 ms 1480 KB Output is correct
60 Correct 3 ms 1480 KB Output is correct
61 Correct 3 ms 2004 KB Output is correct
62 Correct 4 ms 2136 KB Output is correct
63 Correct 6 ms 3684 KB Output is correct
64 Correct 17 ms 3720 KB Output is correct
65 Correct 6 ms 3740 KB Output is correct
66 Correct 6 ms 3740 KB Output is correct
67 Correct 6 ms 3812 KB Output is correct
68 Correct 6 ms 3812 KB Output is correct
69 Correct 6 ms 3812 KB Output is correct
70 Correct 11 ms 5056 KB Output is correct
71 Correct 10 ms 5072 KB Output is correct
72 Correct 13 ms 5072 KB Output is correct
73 Correct 11 ms 5088 KB Output is correct
74 Correct 11 ms 5104 KB Output is correct
75 Correct 11 ms 5104 KB Output is correct
76 Correct 5 ms 5104 KB Output is correct
77 Correct 21 ms 8856 KB Output is correct
78 Correct 21 ms 8856 KB Output is correct
79 Correct 21 ms 8872 KB Output is correct
80 Correct 21 ms 8872 KB Output is correct
81 Correct 21 ms 8872 KB Output is correct
82 Correct 11 ms 8872 KB Output is correct
83 Correct 15 ms 8872 KB Output is correct
84 Correct 13 ms 8872 KB Output is correct
85 Correct 10 ms 8872 KB Output is correct
86 Correct 18 ms 9464 KB Output is correct