답안 #393311

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
393311 2021-04-23T07:35:49 Z JimmyZJX Mountains (IOI17_mountains) C++14
70 / 100
1000 ms 31752 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++) {
		for (int i = 0; i < j; i++) {
			// choose (j-1)
			int last = j - 1;
			int sum = 0;
			for (int k = j - 2; k >= i; k--) {
				if (see[j - 1][k]) {
					sum += dp[k + 1][last];
					last = k;
				}
			}
			sum += dp[i][last];

			// max
			dp[i][j] = max(dp[i][j - 1], sum + 1);
		}
	}


	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
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 31692 KB Output is correct
2 Correct 14 ms 31692 KB Output is correct
3 Correct 13 ms 31692 KB Output is correct
4 Correct 14 ms 31608 KB Output is correct
5 Correct 14 ms 31636 KB Output is correct
6 Correct 14 ms 31648 KB Output is correct
7 Correct 14 ms 31692 KB Output is correct
8 Correct 14 ms 31660 KB Output is correct
9 Correct 14 ms 31700 KB Output is correct
10 Correct 13 ms 31656 KB Output is correct
11 Correct 14 ms 31692 KB Output is correct
12 Correct 13 ms 31692 KB Output is correct
13 Correct 14 ms 31592 KB Output is correct
14 Correct 14 ms 31632 KB Output is correct
15 Correct 14 ms 31692 KB Output is correct
16 Correct 14 ms 31696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 31692 KB Output is correct
2 Correct 14 ms 31692 KB Output is correct
3 Correct 13 ms 31692 KB Output is correct
4 Correct 14 ms 31608 KB Output is correct
5 Correct 14 ms 31636 KB Output is correct
6 Correct 14 ms 31648 KB Output is correct
7 Correct 14 ms 31692 KB Output is correct
8 Correct 14 ms 31660 KB Output is correct
9 Correct 14 ms 31700 KB Output is correct
10 Correct 13 ms 31656 KB Output is correct
11 Correct 14 ms 31692 KB Output is correct
12 Correct 13 ms 31692 KB Output is correct
13 Correct 14 ms 31592 KB Output is correct
14 Correct 14 ms 31632 KB Output is correct
15 Correct 14 ms 31692 KB Output is correct
16 Correct 14 ms 31696 KB Output is correct
17 Correct 14 ms 31692 KB Output is correct
18 Correct 14 ms 31668 KB Output is correct
19 Correct 13 ms 31692 KB Output is correct
20 Correct 14 ms 31608 KB Output is correct
21 Correct 14 ms 31600 KB Output is correct
22 Correct 14 ms 31692 KB Output is correct
23 Correct 14 ms 31660 KB Output is correct
24 Correct 13 ms 31692 KB Output is correct
25 Correct 14 ms 31636 KB Output is correct
26 Correct 14 ms 31692 KB Output is correct
27 Correct 14 ms 31592 KB Output is correct
28 Correct 14 ms 31584 KB Output is correct
29 Correct 14 ms 31692 KB Output is correct
30 Correct 14 ms 31692 KB Output is correct
31 Correct 14 ms 31596 KB Output is correct
32 Correct 14 ms 31688 KB Output is correct
33 Correct 15 ms 31620 KB Output is correct
34 Correct 15 ms 31616 KB Output is correct
35 Correct 14 ms 31608 KB Output is correct
36 Correct 14 ms 31688 KB Output is correct
37 Correct 14 ms 31692 KB Output is correct
38 Correct 14 ms 31672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 31692 KB Output is correct
2 Correct 14 ms 31692 KB Output is correct
3 Correct 13 ms 31692 KB Output is correct
4 Correct 14 ms 31608 KB Output is correct
5 Correct 14 ms 31636 KB Output is correct
6 Correct 14 ms 31648 KB Output is correct
7 Correct 14 ms 31692 KB Output is correct
8 Correct 14 ms 31660 KB Output is correct
9 Correct 14 ms 31700 KB Output is correct
10 Correct 13 ms 31656 KB Output is correct
11 Correct 14 ms 31692 KB Output is correct
12 Correct 13 ms 31692 KB Output is correct
13 Correct 14 ms 31592 KB Output is correct
14 Correct 14 ms 31632 KB Output is correct
15 Correct 14 ms 31692 KB Output is correct
16 Correct 14 ms 31696 KB Output is correct
17 Correct 14 ms 31692 KB Output is correct
18 Correct 14 ms 31668 KB Output is correct
19 Correct 13 ms 31692 KB Output is correct
20 Correct 14 ms 31608 KB Output is correct
21 Correct 14 ms 31600 KB Output is correct
22 Correct 14 ms 31692 KB Output is correct
23 Correct 14 ms 31660 KB Output is correct
24 Correct 13 ms 31692 KB Output is correct
25 Correct 14 ms 31636 KB Output is correct
26 Correct 14 ms 31692 KB Output is correct
27 Correct 14 ms 31592 KB Output is correct
28 Correct 14 ms 31584 KB Output is correct
29 Correct 14 ms 31692 KB Output is correct
30 Correct 14 ms 31692 KB Output is correct
31 Correct 14 ms 31596 KB Output is correct
32 Correct 14 ms 31688 KB Output is correct
33 Correct 15 ms 31620 KB Output is correct
34 Correct 15 ms 31616 KB Output is correct
35 Correct 14 ms 31608 KB Output is correct
36 Correct 14 ms 31688 KB Output is correct
37 Correct 14 ms 31692 KB Output is correct
38 Correct 14 ms 31672 KB Output is correct
39 Correct 15 ms 31692 KB Output is correct
40 Correct 19 ms 31696 KB Output is correct
41 Correct 19 ms 31712 KB Output is correct
42 Correct 19 ms 31660 KB Output is correct
43 Correct 19 ms 31692 KB Output is correct
44 Correct 19 ms 31636 KB Output is correct
45 Correct 20 ms 31652 KB Output is correct
46 Correct 20 ms 31696 KB Output is correct
47 Correct 21 ms 31708 KB Output is correct
48 Correct 24 ms 31680 KB Output is correct
49 Correct 20 ms 31692 KB Output is correct
50 Correct 20 ms 31708 KB Output is correct
51 Correct 19 ms 31672 KB Output is correct
52 Correct 20 ms 31680 KB Output is correct
53 Correct 21 ms 31680 KB Output is correct
54 Correct 22 ms 31664 KB Output is correct
55 Correct 20 ms 31692 KB Output is correct
56 Correct 21 ms 31708 KB Output is correct
57 Correct 19 ms 31708 KB Output is correct
58 Correct 20 ms 31692 KB Output is correct
59 Correct 19 ms 31688 KB Output is correct
60 Correct 21 ms 31752 KB Output is correct
61 Correct 19 ms 31692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 31692 KB Output is correct
2 Correct 14 ms 31692 KB Output is correct
3 Correct 13 ms 31692 KB Output is correct
4 Correct 14 ms 31608 KB Output is correct
5 Correct 14 ms 31636 KB Output is correct
6 Correct 14 ms 31648 KB Output is correct
7 Correct 14 ms 31692 KB Output is correct
8 Correct 14 ms 31660 KB Output is correct
9 Correct 14 ms 31700 KB Output is correct
10 Correct 13 ms 31656 KB Output is correct
11 Correct 14 ms 31692 KB Output is correct
12 Correct 13 ms 31692 KB Output is correct
13 Correct 14 ms 31592 KB Output is correct
14 Correct 14 ms 31632 KB Output is correct
15 Correct 14 ms 31692 KB Output is correct
16 Correct 14 ms 31696 KB Output is correct
17 Correct 14 ms 31692 KB Output is correct
18 Correct 14 ms 31668 KB Output is correct
19 Correct 13 ms 31692 KB Output is correct
20 Correct 14 ms 31608 KB Output is correct
21 Correct 14 ms 31600 KB Output is correct
22 Correct 14 ms 31692 KB Output is correct
23 Correct 14 ms 31660 KB Output is correct
24 Correct 13 ms 31692 KB Output is correct
25 Correct 14 ms 31636 KB Output is correct
26 Correct 14 ms 31692 KB Output is correct
27 Correct 14 ms 31592 KB Output is correct
28 Correct 14 ms 31584 KB Output is correct
29 Correct 14 ms 31692 KB Output is correct
30 Correct 14 ms 31692 KB Output is correct
31 Correct 14 ms 31596 KB Output is correct
32 Correct 14 ms 31688 KB Output is correct
33 Correct 15 ms 31620 KB Output is correct
34 Correct 15 ms 31616 KB Output is correct
35 Correct 14 ms 31608 KB Output is correct
36 Correct 14 ms 31688 KB Output is correct
37 Correct 14 ms 31692 KB Output is correct
38 Correct 14 ms 31672 KB Output is correct
39 Correct 15 ms 31692 KB Output is correct
40 Correct 19 ms 31696 KB Output is correct
41 Correct 19 ms 31712 KB Output is correct
42 Correct 19 ms 31660 KB Output is correct
43 Correct 19 ms 31692 KB Output is correct
44 Correct 19 ms 31636 KB Output is correct
45 Correct 20 ms 31652 KB Output is correct
46 Correct 20 ms 31696 KB Output is correct
47 Correct 21 ms 31708 KB Output is correct
48 Correct 24 ms 31680 KB Output is correct
49 Correct 20 ms 31692 KB Output is correct
50 Correct 20 ms 31708 KB Output is correct
51 Correct 19 ms 31672 KB Output is correct
52 Correct 20 ms 31680 KB Output is correct
53 Correct 21 ms 31680 KB Output is correct
54 Correct 22 ms 31664 KB Output is correct
55 Correct 20 ms 31692 KB Output is correct
56 Correct 21 ms 31708 KB Output is correct
57 Correct 19 ms 31708 KB Output is correct
58 Correct 20 ms 31692 KB Output is correct
59 Correct 19 ms 31688 KB Output is correct
60 Correct 21 ms 31752 KB Output is correct
61 Correct 19 ms 31692 KB Output is correct
62 Correct 182 ms 31704 KB Output is correct
63 Execution timed out 1093 ms 31692 KB Time limit exceeded
64 Halted 0 ms 0 KB -