답안 #74439

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
74439 2018-09-01T10:11:28 Z mjt Mountains (IOI17_mountains) C++11
100 / 100
24 ms 9040 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); // select max_height_node
	
	int ans2 = 0; // don't select this node
	for (int i=pos-1,j; i>=l; i=j) {
		for (j=i-1; j>=l; --j) {  // i can see pos
			if (Judge(j, i, pos)) { // j can't see pos
				if (j == l) ans2 += solve(l, i - 1); 
				continue;
			}
			if (j + 1 <= i - 1) ans2 += solve(j + 1, i - 1); // this Section can't see pos
			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);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 372 KB Output is correct
3 Correct 2 ms 392 KB Output is correct
4 Correct 2 ms 392 KB Output is correct
5 Correct 2 ms 472 KB Output is correct
6 Correct 2 ms 484 KB Output is correct
7 Correct 2 ms 484 KB Output is correct
8 Correct 2 ms 484 KB Output is correct
9 Correct 2 ms 540 KB Output is correct
10 Correct 2 ms 544 KB Output is correct
11 Correct 2 ms 544 KB Output is correct
12 Correct 2 ms 560 KB Output is correct
13 Correct 2 ms 560 KB Output is correct
14 Correct 2 ms 560 KB Output is correct
15 Correct 2 ms 616 KB Output is correct
16 Correct 2 ms 636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 372 KB Output is correct
3 Correct 2 ms 392 KB Output is correct
4 Correct 2 ms 392 KB Output is correct
5 Correct 2 ms 472 KB Output is correct
6 Correct 2 ms 484 KB Output is correct
7 Correct 2 ms 484 KB Output is correct
8 Correct 2 ms 484 KB Output is correct
9 Correct 2 ms 540 KB Output is correct
10 Correct 2 ms 544 KB Output is correct
11 Correct 2 ms 544 KB Output is correct
12 Correct 2 ms 560 KB Output is correct
13 Correct 2 ms 560 KB Output is correct
14 Correct 2 ms 560 KB Output is correct
15 Correct 2 ms 616 KB Output is correct
16 Correct 2 ms 636 KB Output is correct
17 Correct 2 ms 636 KB Output is correct
18 Correct 2 ms 636 KB Output is correct
19 Correct 2 ms 636 KB Output is correct
20 Correct 2 ms 636 KB Output is correct
21 Correct 2 ms 636 KB Output is correct
22 Correct 2 ms 704 KB Output is correct
23 Correct 1 ms 704 KB Output is correct
24 Correct 2 ms 704 KB Output is correct
25 Correct 2 ms 704 KB Output is correct
26 Correct 2 ms 704 KB Output is correct
27 Correct 2 ms 704 KB Output is correct
28 Correct 2 ms 704 KB Output is correct
29 Correct 2 ms 704 KB Output is correct
30 Correct 2 ms 704 KB Output is correct
31 Correct 2 ms 704 KB Output is correct
32 Correct 2 ms 704 KB Output is correct
33 Correct 2 ms 704 KB Output is correct
34 Correct 2 ms 704 KB Output is correct
35 Correct 2 ms 704 KB Output is correct
36 Correct 2 ms 704 KB Output is correct
37 Correct 2 ms 764 KB Output is correct
38 Correct 2 ms 764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 372 KB Output is correct
3 Correct 2 ms 392 KB Output is correct
4 Correct 2 ms 392 KB Output is correct
5 Correct 2 ms 472 KB Output is correct
6 Correct 2 ms 484 KB Output is correct
7 Correct 2 ms 484 KB Output is correct
8 Correct 2 ms 484 KB Output is correct
9 Correct 2 ms 540 KB Output is correct
10 Correct 2 ms 544 KB Output is correct
11 Correct 2 ms 544 KB Output is correct
12 Correct 2 ms 560 KB Output is correct
13 Correct 2 ms 560 KB Output is correct
14 Correct 2 ms 560 KB Output is correct
15 Correct 2 ms 616 KB Output is correct
16 Correct 2 ms 636 KB Output is correct
17 Correct 2 ms 636 KB Output is correct
18 Correct 2 ms 636 KB Output is correct
19 Correct 2 ms 636 KB Output is correct
20 Correct 2 ms 636 KB Output is correct
21 Correct 2 ms 636 KB Output is correct
22 Correct 2 ms 704 KB Output is correct
23 Correct 1 ms 704 KB Output is correct
24 Correct 2 ms 704 KB Output is correct
25 Correct 2 ms 704 KB Output is correct
26 Correct 2 ms 704 KB Output is correct
27 Correct 2 ms 704 KB Output is correct
28 Correct 2 ms 704 KB Output is correct
29 Correct 2 ms 704 KB Output is correct
30 Correct 2 ms 704 KB Output is correct
31 Correct 2 ms 704 KB Output is correct
32 Correct 2 ms 704 KB Output is correct
33 Correct 2 ms 704 KB Output is correct
34 Correct 2 ms 704 KB Output is correct
35 Correct 2 ms 704 KB Output is correct
36 Correct 2 ms 704 KB Output is correct
37 Correct 2 ms 764 KB Output is correct
38 Correct 2 ms 764 KB Output is correct
39 Correct 3 ms 892 KB Output is correct
40 Correct 3 ms 1020 KB Output is correct
41 Correct 2 ms 1020 KB Output is correct
42 Correct 2 ms 1020 KB Output is correct
43 Correct 3 ms 1020 KB Output is correct
44 Correct 2 ms 1020 KB Output is correct
45 Correct 3 ms 1020 KB Output is correct
46 Correct 3 ms 1020 KB Output is correct
47 Correct 3 ms 1148 KB Output is correct
48 Correct 2 ms 1148 KB Output is correct
49 Correct 3 ms 1148 KB Output is correct
50 Correct 3 ms 1148 KB Output is correct
51 Correct 2 ms 1148 KB Output is correct
52 Correct 5 ms 1276 KB Output is correct
53 Correct 3 ms 1276 KB Output is correct
54 Correct 4 ms 1276 KB Output is correct
55 Correct 4 ms 1276 KB Output is correct
56 Correct 4 ms 1280 KB Output is correct
57 Correct 2 ms 1280 KB Output is correct
58 Correct 3 ms 1280 KB Output is correct
59 Correct 3 ms 1280 KB Output is correct
60 Correct 2 ms 1280 KB Output is correct
61 Correct 3 ms 1788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 372 KB Output is correct
3 Correct 2 ms 392 KB Output is correct
4 Correct 2 ms 392 KB Output is correct
5 Correct 2 ms 472 KB Output is correct
6 Correct 2 ms 484 KB Output is correct
7 Correct 2 ms 484 KB Output is correct
8 Correct 2 ms 484 KB Output is correct
9 Correct 2 ms 540 KB Output is correct
10 Correct 2 ms 544 KB Output is correct
11 Correct 2 ms 544 KB Output is correct
12 Correct 2 ms 560 KB Output is correct
13 Correct 2 ms 560 KB Output is correct
14 Correct 2 ms 560 KB Output is correct
15 Correct 2 ms 616 KB Output is correct
16 Correct 2 ms 636 KB Output is correct
17 Correct 2 ms 636 KB Output is correct
18 Correct 2 ms 636 KB Output is correct
19 Correct 2 ms 636 KB Output is correct
20 Correct 2 ms 636 KB Output is correct
21 Correct 2 ms 636 KB Output is correct
22 Correct 2 ms 704 KB Output is correct
23 Correct 1 ms 704 KB Output is correct
24 Correct 2 ms 704 KB Output is correct
25 Correct 2 ms 704 KB Output is correct
26 Correct 2 ms 704 KB Output is correct
27 Correct 2 ms 704 KB Output is correct
28 Correct 2 ms 704 KB Output is correct
29 Correct 2 ms 704 KB Output is correct
30 Correct 2 ms 704 KB Output is correct
31 Correct 2 ms 704 KB Output is correct
32 Correct 2 ms 704 KB Output is correct
33 Correct 2 ms 704 KB Output is correct
34 Correct 2 ms 704 KB Output is correct
35 Correct 2 ms 704 KB Output is correct
36 Correct 2 ms 704 KB Output is correct
37 Correct 2 ms 764 KB Output is correct
38 Correct 2 ms 764 KB Output is correct
39 Correct 3 ms 892 KB Output is correct
40 Correct 3 ms 1020 KB Output is correct
41 Correct 2 ms 1020 KB Output is correct
42 Correct 2 ms 1020 KB Output is correct
43 Correct 3 ms 1020 KB Output is correct
44 Correct 2 ms 1020 KB Output is correct
45 Correct 3 ms 1020 KB Output is correct
46 Correct 3 ms 1020 KB Output is correct
47 Correct 3 ms 1148 KB Output is correct
48 Correct 2 ms 1148 KB Output is correct
49 Correct 3 ms 1148 KB Output is correct
50 Correct 3 ms 1148 KB Output is correct
51 Correct 2 ms 1148 KB Output is correct
52 Correct 5 ms 1276 KB Output is correct
53 Correct 3 ms 1276 KB Output is correct
54 Correct 4 ms 1276 KB Output is correct
55 Correct 4 ms 1276 KB Output is correct
56 Correct 4 ms 1280 KB Output is correct
57 Correct 2 ms 1280 KB Output is correct
58 Correct 3 ms 1280 KB Output is correct
59 Correct 3 ms 1280 KB Output is correct
60 Correct 2 ms 1280 KB Output is correct
61 Correct 3 ms 1788 KB Output is correct
62 Correct 4 ms 1916 KB Output is correct
63 Correct 6 ms 3324 KB Output is correct
64 Correct 6 ms 3324 KB Output is correct
65 Correct 6 ms 3324 KB Output is correct
66 Correct 6 ms 3324 KB Output is correct
67 Correct 8 ms 3324 KB Output is correct
68 Correct 6 ms 3324 KB Output is correct
69 Correct 6 ms 3324 KB Output is correct
70 Correct 12 ms 4604 KB Output is correct
71 Correct 11 ms 4604 KB Output is correct
72 Correct 11 ms 4604 KB Output is correct
73 Correct 11 ms 4604 KB Output is correct
74 Correct 11 ms 4604 KB Output is correct
75 Correct 12 ms 4604 KB Output is correct
76 Correct 5 ms 4604 KB Output is correct
77 Correct 22 ms 8316 KB Output is correct
78 Correct 21 ms 8316 KB Output is correct
79 Correct 24 ms 8316 KB Output is correct
80 Correct 21 ms 8316 KB Output is correct
81 Correct 22 ms 8316 KB Output is correct
82 Correct 10 ms 8316 KB Output is correct
83 Correct 16 ms 8316 KB Output is correct
84 Correct 13 ms 8316 KB Output is correct
85 Correct 11 ms 8316 KB Output is correct
86 Correct 18 ms 9040 KB Output is correct