Submission #393315

# Submission time Handle Problem Language Result Execution time Memory
393315 2021-04-23T07:40:45 Z JimmyZJX Mountains (IOI17_mountains) C++14
100 / 100
45 ms 31724 KB
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cstring>
#include <climits>
#include <cassert>
#include <tuple>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <numeric>

using namespace std;

typedef long long LL;
typedef vector<int> Vi;
typedef vector<LL> VL;
typedef vector<bool> Vb;
typedef vector<vector<int>> Vii;

#define forR(i, n) for (int i = 0; i < (n); i++)

template <typename T>
vector<size_t> sort_indexes(vector<T> v) {
	vector<size_t> idx(v.size());
	iota(idx.begin(), idx.end(), 0);

	stable_sort(idx.begin(), idx.end(),
		[&v](size_t i1, size_t i2) {return v[i1] < v[i2]; });

	return idx;
}

int see[2003][2003];
int dp[2003][2003];

struct Frac { // a / b
	int a, b;
};

bool ge(Frac x, Frac y) {
	return (LL)x.a * y.b >= (LL)y.a * x.b;
}

int maximum_deevs(Vi y) {
	int n = y.size();
	memset(see, 0, sizeof(see));

	Vi cnt(n);

	forR(i, n) {
		Frac view{ INT_MIN, 1 };
		for (int j = i - 1; j >= 0; j--) {
			Frac vj{ y[j] - y[i], i - j };
			if (ge(vj, view)) {
				view = vj;
				see[i][j] = 1;
				cnt[i]++;
			}
		}
		view = { INT_MIN, 1 };
		for (int j = i + 1; j < n; j++) {
			Frac vj{ y[j] - y[i], j - i };
			if (ge(vj, view)) {
				view = vj;
				see[i][j] = 1;
				cnt[i]++;
			}
		}
	}

	memset(dp, 0, sizeof(dp));
	// dp[i][j]   [i, j)
	forR(i, n) dp[i][i] = 0;

	for (int j = 1; j <= n; j++) {
		dp[j - 1][j] = 1;
		// choose (j-1)
		int last = j - 1;
		int sum = 1;
		for (int k = j - 2; k >= 0; k--) {
			if (see[j - 1][k]) {
				sum += dp[k + 1][last];
				last = k;
			}
			dp[k][j] = max(dp[k][j - 1], dp[k][last] + sum);
		}
	}


	return dp[0][n];
}


#ifdef TEST_LOCAL
int main() {
	auto r = maximum_deevs(Vi{ 0,1,1000000,1500001,1499997,1499992,1499986,1499979,1499971,1499962,1499952,1499941,1499929,1499916,1499902,1499887,1499871,1499854,1000000000 });

	return 0;
}
#endif
# Verdict Execution time Memory Grader output
1 Correct 13 ms 31692 KB Output is correct
2 Correct 13 ms 31692 KB Output is correct
3 Correct 15 ms 31692 KB Output is correct
4 Correct 14 ms 31648 KB Output is correct
5 Correct 13 ms 31692 KB Output is correct
6 Correct 13 ms 31700 KB Output is correct
7 Correct 13 ms 31588 KB Output is correct
8 Correct 14 ms 31700 KB Output is correct
9 Correct 14 ms 31692 KB Output is correct
10 Correct 16 ms 31708 KB Output is correct
11 Correct 13 ms 31692 KB Output is correct
12 Correct 14 ms 31692 KB Output is correct
13 Correct 14 ms 31672 KB Output is correct
14 Correct 14 ms 31692 KB Output is correct
15 Correct 14 ms 31580 KB Output is correct
16 Correct 14 ms 31628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 31692 KB Output is correct
2 Correct 13 ms 31692 KB Output is correct
3 Correct 15 ms 31692 KB Output is correct
4 Correct 14 ms 31648 KB Output is correct
5 Correct 13 ms 31692 KB Output is correct
6 Correct 13 ms 31700 KB Output is correct
7 Correct 13 ms 31588 KB Output is correct
8 Correct 14 ms 31700 KB Output is correct
9 Correct 14 ms 31692 KB Output is correct
10 Correct 16 ms 31708 KB Output is correct
11 Correct 13 ms 31692 KB Output is correct
12 Correct 14 ms 31692 KB Output is correct
13 Correct 14 ms 31672 KB Output is correct
14 Correct 14 ms 31692 KB Output is correct
15 Correct 14 ms 31580 KB Output is correct
16 Correct 14 ms 31628 KB Output is correct
17 Correct 14 ms 31696 KB Output is correct
18 Correct 13 ms 31692 KB Output is correct
19 Correct 14 ms 31636 KB Output is correct
20 Correct 15 ms 31592 KB Output is correct
21 Correct 14 ms 31692 KB Output is correct
22 Correct 14 ms 31692 KB Output is correct
23 Correct 14 ms 31692 KB Output is correct
24 Correct 14 ms 31692 KB Output is correct
25 Correct 14 ms 31668 KB Output is correct
26 Correct 14 ms 31588 KB Output is correct
27 Correct 13 ms 31668 KB Output is correct
28 Correct 14 ms 31692 KB Output is correct
29 Correct 14 ms 31632 KB Output is correct
30 Correct 15 ms 31692 KB Output is correct
31 Correct 16 ms 31692 KB Output is correct
32 Correct 16 ms 31660 KB Output is correct
33 Correct 15 ms 31612 KB Output is correct
34 Correct 14 ms 31692 KB Output is correct
35 Correct 14 ms 31692 KB Output is correct
36 Correct 14 ms 31600 KB Output is correct
37 Correct 14 ms 31692 KB Output is correct
38 Correct 14 ms 31676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 31692 KB Output is correct
2 Correct 13 ms 31692 KB Output is correct
3 Correct 15 ms 31692 KB Output is correct
4 Correct 14 ms 31648 KB Output is correct
5 Correct 13 ms 31692 KB Output is correct
6 Correct 13 ms 31700 KB Output is correct
7 Correct 13 ms 31588 KB Output is correct
8 Correct 14 ms 31700 KB Output is correct
9 Correct 14 ms 31692 KB Output is correct
10 Correct 16 ms 31708 KB Output is correct
11 Correct 13 ms 31692 KB Output is correct
12 Correct 14 ms 31692 KB Output is correct
13 Correct 14 ms 31672 KB Output is correct
14 Correct 14 ms 31692 KB Output is correct
15 Correct 14 ms 31580 KB Output is correct
16 Correct 14 ms 31628 KB Output is correct
17 Correct 14 ms 31696 KB Output is correct
18 Correct 13 ms 31692 KB Output is correct
19 Correct 14 ms 31636 KB Output is correct
20 Correct 15 ms 31592 KB Output is correct
21 Correct 14 ms 31692 KB Output is correct
22 Correct 14 ms 31692 KB Output is correct
23 Correct 14 ms 31692 KB Output is correct
24 Correct 14 ms 31692 KB Output is correct
25 Correct 14 ms 31668 KB Output is correct
26 Correct 14 ms 31588 KB Output is correct
27 Correct 13 ms 31668 KB Output is correct
28 Correct 14 ms 31692 KB Output is correct
29 Correct 14 ms 31632 KB Output is correct
30 Correct 15 ms 31692 KB Output is correct
31 Correct 16 ms 31692 KB Output is correct
32 Correct 16 ms 31660 KB Output is correct
33 Correct 15 ms 31612 KB Output is correct
34 Correct 14 ms 31692 KB Output is correct
35 Correct 14 ms 31692 KB Output is correct
36 Correct 14 ms 31600 KB Output is correct
37 Correct 14 ms 31692 KB Output is correct
38 Correct 14 ms 31676 KB Output is correct
39 Correct 14 ms 31684 KB Output is correct
40 Correct 14 ms 31620 KB Output is correct
41 Correct 15 ms 31672 KB Output is correct
42 Correct 16 ms 31704 KB Output is correct
43 Correct 14 ms 31612 KB Output is correct
44 Correct 15 ms 31648 KB Output is correct
45 Correct 15 ms 31692 KB Output is correct
46 Correct 14 ms 31660 KB Output is correct
47 Correct 16 ms 31608 KB Output is correct
48 Correct 16 ms 31676 KB Output is correct
49 Correct 15 ms 31692 KB Output is correct
50 Correct 14 ms 31692 KB Output is correct
51 Correct 14 ms 31696 KB Output is correct
52 Correct 14 ms 31680 KB Output is correct
53 Correct 14 ms 31684 KB Output is correct
54 Correct 16 ms 31692 KB Output is correct
55 Correct 14 ms 31680 KB Output is correct
56 Correct 14 ms 31700 KB Output is correct
57 Correct 17 ms 31692 KB Output is correct
58 Correct 16 ms 31692 KB Output is correct
59 Correct 14 ms 31648 KB Output is correct
60 Correct 14 ms 31692 KB Output is correct
61 Correct 14 ms 31692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 31692 KB Output is correct
2 Correct 13 ms 31692 KB Output is correct
3 Correct 15 ms 31692 KB Output is correct
4 Correct 14 ms 31648 KB Output is correct
5 Correct 13 ms 31692 KB Output is correct
6 Correct 13 ms 31700 KB Output is correct
7 Correct 13 ms 31588 KB Output is correct
8 Correct 14 ms 31700 KB Output is correct
9 Correct 14 ms 31692 KB Output is correct
10 Correct 16 ms 31708 KB Output is correct
11 Correct 13 ms 31692 KB Output is correct
12 Correct 14 ms 31692 KB Output is correct
13 Correct 14 ms 31672 KB Output is correct
14 Correct 14 ms 31692 KB Output is correct
15 Correct 14 ms 31580 KB Output is correct
16 Correct 14 ms 31628 KB Output is correct
17 Correct 14 ms 31696 KB Output is correct
18 Correct 13 ms 31692 KB Output is correct
19 Correct 14 ms 31636 KB Output is correct
20 Correct 15 ms 31592 KB Output is correct
21 Correct 14 ms 31692 KB Output is correct
22 Correct 14 ms 31692 KB Output is correct
23 Correct 14 ms 31692 KB Output is correct
24 Correct 14 ms 31692 KB Output is correct
25 Correct 14 ms 31668 KB Output is correct
26 Correct 14 ms 31588 KB Output is correct
27 Correct 13 ms 31668 KB Output is correct
28 Correct 14 ms 31692 KB Output is correct
29 Correct 14 ms 31632 KB Output is correct
30 Correct 15 ms 31692 KB Output is correct
31 Correct 16 ms 31692 KB Output is correct
32 Correct 16 ms 31660 KB Output is correct
33 Correct 15 ms 31612 KB Output is correct
34 Correct 14 ms 31692 KB Output is correct
35 Correct 14 ms 31692 KB Output is correct
36 Correct 14 ms 31600 KB Output is correct
37 Correct 14 ms 31692 KB Output is correct
38 Correct 14 ms 31676 KB Output is correct
39 Correct 14 ms 31684 KB Output is correct
40 Correct 14 ms 31620 KB Output is correct
41 Correct 15 ms 31672 KB Output is correct
42 Correct 16 ms 31704 KB Output is correct
43 Correct 14 ms 31612 KB Output is correct
44 Correct 15 ms 31648 KB Output is correct
45 Correct 15 ms 31692 KB Output is correct
46 Correct 14 ms 31660 KB Output is correct
47 Correct 16 ms 31608 KB Output is correct
48 Correct 16 ms 31676 KB Output is correct
49 Correct 15 ms 31692 KB Output is correct
50 Correct 14 ms 31692 KB Output is correct
51 Correct 14 ms 31696 KB Output is correct
52 Correct 14 ms 31680 KB Output is correct
53 Correct 14 ms 31684 KB Output is correct
54 Correct 16 ms 31692 KB Output is correct
55 Correct 14 ms 31680 KB Output is correct
56 Correct 14 ms 31700 KB Output is correct
57 Correct 17 ms 31692 KB Output is correct
58 Correct 16 ms 31692 KB Output is correct
59 Correct 14 ms 31648 KB Output is correct
60 Correct 14 ms 31692 KB Output is correct
61 Correct 14 ms 31692 KB Output is correct
62 Correct 17 ms 31636 KB Output is correct
63 Correct 26 ms 31724 KB Output is correct
64 Correct 31 ms 31664 KB Output is correct
65 Correct 30 ms 31692 KB Output is correct
66 Correct 30 ms 31640 KB Output is correct
67 Correct 30 ms 31668 KB Output is correct
68 Correct 30 ms 31656 KB Output is correct
69 Correct 30 ms 31656 KB Output is correct
70 Correct 43 ms 31692 KB Output is correct
71 Correct 37 ms 31720 KB Output is correct
72 Correct 40 ms 31664 KB Output is correct
73 Correct 36 ms 31680 KB Output is correct
74 Correct 36 ms 31684 KB Output is correct
75 Correct 36 ms 31628 KB Output is correct
76 Correct 30 ms 31684 KB Output is correct
77 Correct 45 ms 31632 KB Output is correct
78 Correct 45 ms 31632 KB Output is correct
79 Correct 44 ms 31692 KB Output is correct
80 Correct 44 ms 31692 KB Output is correct
81 Correct 44 ms 31660 KB Output is correct
82 Correct 30 ms 31708 KB Output is correct
83 Correct 32 ms 31692 KB Output is correct
84 Correct 36 ms 31724 KB Output is correct
85 Correct 30 ms 31664 KB Output is correct
86 Correct 31 ms 31668 KB Output is correct