Submission #64203

# Submission time Handle Problem Language Result Execution time Memory
64203 2018-08-03T13:38:10 Z gs14004 None (KOI18_footprint) C++17
100 / 100
1787 ms 84672 KB
#include <bits/stdc++.h>
using namespace std;
using pi = pair<int, int>;
using lint = long long;
const int MAXN = 3005;

int n;
pi a[MAXN];
pi dp[MAXN][MAXN][2];
int idx[MAXN];

struct st{
	pi pnt;
	int idx;
};

lint ccw(pi a, pi b, pi c){
	int dx1 = b.first - a.first;
	int dy1 = b.second - a.second;
	int dx2 = c.first - a.first;
	int dy2 = c.second - a.second;
	return 1ll * dx1 * dy2 - 1ll * dy1 * dx2;
}

void trace(int x, int y, int z){
	printf("%d %d\n", a[y].first, a[y].second);
	if(dp[x][y][z].first == 0) return;
	trace(y, dp[x][y][z].second, 1-z);
}

int main(){
	cin >> n;
	for(int i=0; i<n; i++) cin >> a[i].first >> a[i].second;
	sort(a, a+n, [&](const pi &a, const pi &b){
		return a.second < b.second;
	});
	sort(a+1, a+n, [&](const pi &p, const pi &q){
		return ccw(a[0], p, q) > 0;
	});
	int grp = 1;
	for(int i=1; i<n; i++){
		if(ccw(a[0], a[i-1], a[i]) != 0) grp++;
		idx[i] = grp;
	}
	for(int i=n-1; i>=1; i--){
		vector<int> up, dn;
		for(int j=1; j<n; j++){
			if(idx[j] < idx[i]) dn.push_back(j);
			if(idx[j] > idx[i]) up.push_back(j);
		}
		sort(up.begin(), up.end(), [&](const int &p, const int &q){
			return ccw(a[i], a[p], a[q]) > 0;
		});
		sort(dn.begin(), dn.end(), [&](const int &p, const int &q){
			return ccw(a[i], a[p], a[q]) > 0;
		});
		int ptr = 0;
		pi curmax = pi(-1e9, -1);
		for(auto &j : dn){
			while(ptr < up.size() && ccw(a[j], a[i], a[up[ptr]]) < 0){
				auto l = dp[i][up[ptr]][0].first + 1;
				curmax = max(curmax, pi(l, up[ptr]));
				ptr++;
			}
			dp[j][i][1]= curmax;
		}
		reverse(dn.begin(), dn.end());
		reverse(up.begin(), up.end());
		ptr = 0;
		curmax = pi(0, -1);
		for(auto &j : dn){
			while(ptr < up.size() && ccw(a[j], a[i], a[up[ptr]]) > 0){
				auto l = dp[i][up[ptr]][1].first + 1;
				curmax = max(curmax, pi(l, up[ptr]));
				ptr++;
			}
			dp[j][i][0]= curmax;
		}
	}
	tuple<int, int, int> ans = make_tuple(-100, -1, -1);
	for(int i=n-1; i>=1; i--){
		for(int j=i+1; j<n; j++){
			if(idx[i] == idx[j]) continue;
			ans = max(ans, make_tuple(dp[i][j][1].first, i, j));
		}
	}
	int x, y, z; tie(x, y, z) = ans;
	if(x < 0){
		puts("0");
		return 0;
	}	
	cout << x + 3 << endl;
	printf("%d %d\n", a[0].first, a[0].second);
	printf("%d %d\n", a[y].first, a[y].second);
	trace(y, z, 1);
}

Compilation message

footprint.cpp: In function 'int main()':
footprint.cpp:60:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    while(ptr < up.size() && ccw(a[j], a[i], a[up[ptr]]) < 0){
          ~~~~^~~~~~~~~~~
footprint.cpp:72:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    while(ptr < up.size() && ccw(a[j], a[i], a[up[ptr]]) > 0){
          ~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1364 ms 69964 KB Output is correct
2 Correct 1445 ms 72764 KB Output is correct
3 Correct 1389 ms 72764 KB Output is correct
4 Correct 1135 ms 73108 KB Output is correct
5 Correct 1173 ms 73108 KB Output is correct
6 Correct 1242 ms 73276 KB Output is correct
7 Correct 1427 ms 73276 KB Output is correct
8 Correct 1482 ms 73692 KB Output is correct
9 Correct 1409 ms 73856 KB Output is correct
10 Correct 1423 ms 73856 KB Output is correct
11 Correct 1449 ms 73856 KB Output is correct
12 Correct 1475 ms 74136 KB Output is correct
13 Correct 1501 ms 75616 KB Output is correct
14 Correct 1455 ms 75616 KB Output is correct
15 Correct 1437 ms 75616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 75616 KB Output is correct
2 Correct 4 ms 75616 KB Output is correct
3 Correct 3 ms 75616 KB Output is correct
4 Correct 0 ms 75616 KB Output is correct
5 Correct 3 ms 75616 KB Output is correct
6 Correct 3 ms 75616 KB Output is correct
7 Correct 2 ms 75616 KB Output is correct
8 Correct 1 ms 75616 KB Output is correct
9 Correct 3 ms 75616 KB Output is correct
10 Correct 3 ms 75616 KB Output is correct
11 Correct 3 ms 75616 KB Output is correct
12 Correct 2 ms 75616 KB Output is correct
13 Correct 3 ms 75616 KB Output is correct
14 Correct 3 ms 75616 KB Output is correct
15 Correct 3 ms 75616 KB Output is correct
16 Correct 3 ms 75616 KB Output is correct
17 Correct 3 ms 75616 KB Output is correct
18 Correct 3 ms 75616 KB Output is correct
19 Correct 4 ms 75616 KB Output is correct
20 Correct 3 ms 75616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 75616 KB Output is correct
2 Correct 4 ms 75616 KB Output is correct
3 Correct 3 ms 75616 KB Output is correct
4 Correct 0 ms 75616 KB Output is correct
5 Correct 3 ms 75616 KB Output is correct
6 Correct 3 ms 75616 KB Output is correct
7 Correct 2 ms 75616 KB Output is correct
8 Correct 1 ms 75616 KB Output is correct
9 Correct 3 ms 75616 KB Output is correct
10 Correct 3 ms 75616 KB Output is correct
11 Correct 3 ms 75616 KB Output is correct
12 Correct 2 ms 75616 KB Output is correct
13 Correct 3 ms 75616 KB Output is correct
14 Correct 3 ms 75616 KB Output is correct
15 Correct 3 ms 75616 KB Output is correct
16 Correct 3 ms 75616 KB Output is correct
17 Correct 3 ms 75616 KB Output is correct
18 Correct 3 ms 75616 KB Output is correct
19 Correct 4 ms 75616 KB Output is correct
20 Correct 3 ms 75616 KB Output is correct
21 Correct 17 ms 75616 KB Output is correct
22 Correct 17 ms 75616 KB Output is correct
23 Correct 16 ms 75616 KB Output is correct
24 Correct 19 ms 75616 KB Output is correct
25 Correct 18 ms 75616 KB Output is correct
26 Correct 19 ms 75616 KB Output is correct
27 Correct 18 ms 75616 KB Output is correct
28 Correct 16 ms 75616 KB Output is correct
29 Correct 18 ms 75616 KB Output is correct
30 Correct 21 ms 75616 KB Output is correct
31 Correct 18 ms 75616 KB Output is correct
32 Correct 16 ms 75616 KB Output is correct
33 Correct 13 ms 75616 KB Output is correct
34 Correct 11 ms 75616 KB Output is correct
35 Correct 13 ms 75616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1364 ms 69964 KB Output is correct
2 Correct 1445 ms 72764 KB Output is correct
3 Correct 1389 ms 72764 KB Output is correct
4 Correct 1135 ms 73108 KB Output is correct
5 Correct 1173 ms 73108 KB Output is correct
6 Correct 1242 ms 73276 KB Output is correct
7 Correct 1427 ms 73276 KB Output is correct
8 Correct 1482 ms 73692 KB Output is correct
9 Correct 1409 ms 73856 KB Output is correct
10 Correct 1423 ms 73856 KB Output is correct
11 Correct 1449 ms 73856 KB Output is correct
12 Correct 1475 ms 74136 KB Output is correct
13 Correct 1501 ms 75616 KB Output is correct
14 Correct 1455 ms 75616 KB Output is correct
15 Correct 1437 ms 75616 KB Output is correct
16 Correct 3 ms 75616 KB Output is correct
17 Correct 4 ms 75616 KB Output is correct
18 Correct 3 ms 75616 KB Output is correct
19 Correct 0 ms 75616 KB Output is correct
20 Correct 3 ms 75616 KB Output is correct
21 Correct 3 ms 75616 KB Output is correct
22 Correct 2 ms 75616 KB Output is correct
23 Correct 1 ms 75616 KB Output is correct
24 Correct 3 ms 75616 KB Output is correct
25 Correct 3 ms 75616 KB Output is correct
26 Correct 3 ms 75616 KB Output is correct
27 Correct 2 ms 75616 KB Output is correct
28 Correct 3 ms 75616 KB Output is correct
29 Correct 3 ms 75616 KB Output is correct
30 Correct 3 ms 75616 KB Output is correct
31 Correct 3 ms 75616 KB Output is correct
32 Correct 3 ms 75616 KB Output is correct
33 Correct 3 ms 75616 KB Output is correct
34 Correct 4 ms 75616 KB Output is correct
35 Correct 3 ms 75616 KB Output is correct
36 Correct 17 ms 75616 KB Output is correct
37 Correct 17 ms 75616 KB Output is correct
38 Correct 16 ms 75616 KB Output is correct
39 Correct 19 ms 75616 KB Output is correct
40 Correct 18 ms 75616 KB Output is correct
41 Correct 19 ms 75616 KB Output is correct
42 Correct 18 ms 75616 KB Output is correct
43 Correct 16 ms 75616 KB Output is correct
44 Correct 18 ms 75616 KB Output is correct
45 Correct 21 ms 75616 KB Output is correct
46 Correct 18 ms 75616 KB Output is correct
47 Correct 16 ms 75616 KB Output is correct
48 Correct 13 ms 75616 KB Output is correct
49 Correct 11 ms 75616 KB Output is correct
50 Correct 13 ms 75616 KB Output is correct
51 Correct 1448 ms 75616 KB Output is correct
52 Correct 1530 ms 75616 KB Output is correct
53 Correct 1502 ms 75752 KB Output is correct
54 Correct 1736 ms 84104 KB Output is correct
55 Correct 1673 ms 84120 KB Output is correct
56 Correct 1786 ms 84176 KB Output is correct
57 Correct 1787 ms 84176 KB Output is correct
58 Correct 1693 ms 84176 KB Output is correct
59 Correct 1643 ms 84212 KB Output is correct
60 Correct 1610 ms 84324 KB Output is correct
61 Correct 1605 ms 84500 KB Output is correct
62 Correct 1593 ms 84500 KB Output is correct
63 Correct 773 ms 84500 KB Output is correct
64 Correct 831 ms 84500 KB Output is correct
65 Correct 700 ms 84592 KB Output is correct
66 Correct 1026 ms 84592 KB Output is correct
67 Correct 967 ms 84592 KB Output is correct
68 Correct 1022 ms 84672 KB Output is correct