Submission #894726

# Submission time Handle Problem Language Result Execution time Memory
894726 2023-12-28T19:49:30 Z rainboy None (KOI18_footprint) C
100 / 100
1236 ms 71264 KB
#include <stdio.h>

#define N	3000

int max(int a, int b) { return a > b ? a : b; }

unsigned int Z = 12345;

int rand_() {
	return (Z *= 3) >> 1;
}

int xx[N], yy[N];

long long cross(int i, int j, int k) {
	return (long long) (xx[j] - xx[i]) * (yy[k] - yy[i]) - (long long) (xx[k] - xx[i]) * (yy[j] - yy[i]);
}

int o;

void sort(int *ii, int l, int r) {
	while (l < r) {
		int i = l, j = l, k = r, i_ = ii[l + rand_() % (r - l)], tmp;

		while (j < k) {
			long long c = cross(o, ii[j], i_);

			if (c == 0)
				j++;
			else if (c < 0) {
				tmp = ii[i], ii[i] = ii[j], ii[j] = tmp;
				i++, j++;
			} else {
				k--;
				tmp = ii[j], ii[j] = ii[k], ii[k] = tmp;
			}
		}
		sort(ii, l, i);
		l = k;
	}
}

int main() {
	static int hh[N], ii[N], jj[N], dp[N][N], dq[N][N];
	int n, ml, mr, h, h_, i, i0, i_, j, j_, x;

	scanf("%d", &n);
	i0 = -1;
	for (i = 0; i < n; i++) {
		scanf("%d%d", &xx[i], &yy[i]);
		if (i0 == -1 || yy[i0] > yy[i])
			i0 = i;
	}
	for (i = 0; i < n; i++)
		ii[i] = i;
	ii[0] = i0, ii[i0] = 0;
	o = i0, sort(ii, 1, n);
	for (i = 1; i < n; i++) {
		i_ = ii[i];
		ml = 0;
		for (h = 1; h < i; h++)
			if (cross(i0, ii[h], i_) < 0)
				hh[ml++] = ii[h];
		o = i_, sort(hh, 0, ml);
		mr = 0;
		for (j = i + 1; j < n; j++)
			if (cross(i0, i_, ii[j]) < 0)
				jj[mr++] = ii[j];
		o = i_, sort(jj, 0, mr);
		h = 0, j = 0, x = 0;
		while (j < mr) {
			h_ = h == ml ? -1 : hh[h], j_ = jj[j];
			if (h < ml && cross(h_, i_, j_) < 0)
				x = max(x, dq[h_][i_]), h++;
			else
				dp[i_][j_] = x, j++;
		}
		h = ml - 1, j = mr - 1, x = -1;
		while (j >= 0) {
			h_ = h < 0 ? -1 : hh[h], j_ = jj[j];
			if (h >= 0 && cross(h_, i_, j_) > 0)
				x = max(x, dp[h_][i_]), h--;
			else
				dq[i_][j_] = x + 1, j--;
		}
	}
	x = 0;
	for (i = 0; i < n; i++)
		for (j = 0; j < n; j++)
			x = max(x, dq[i][j]);
	if (x == 0) {
		printf("0\n");
		return 0;
	}
	printf("%d\n", (x + 1) * 2);
	for (i = 0; i < n; i++)
		for (j = 0; j < n; j++)
			if (dq[i][j] == x)
				goto out;
out:
	printf("%d %d\n", xx[i0], yy[i0]);
	printf("%d %d\n", xx[j], yy[j]);
	printf("%d %d\n", xx[i], yy[i]);
	while (1) {
		for (h = 0; h < n; h++)
			if (cross(i0, h, i) < 0 && cross(h, i, j) > 0 && dq[i][j] == dp[h][i] + 1) {
				printf("%d %d\n", xx[h], yy[h]);
				j = i, i = h;
				break;
			}
		if (dp[i][j] == 0)
			break;
		for (h = 0; h < n; h++)
			if (cross(i0, h, i) < 0 && cross(h, i, j) < 0 && dp[i][j] == dq[h][i]) {
				printf("%d %d\n", xx[h], yy[h]);
				j = i, i = h;
				break;
			}
	}
	return 0;
}

Compilation message

footprint.c: In function 'main':
footprint.c:47:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
footprint.c:50:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |   scanf("%d%d", &xx[i], &yy[i]);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1029 ms 69188 KB Output is correct
2 Correct 1078 ms 69856 KB Output is correct
3 Correct 1027 ms 69624 KB Output is correct
4 Correct 1055 ms 69380 KB Output is correct
5 Correct 1032 ms 69252 KB Output is correct
6 Correct 1055 ms 69460 KB Output is correct
7 Correct 1045 ms 69364 KB Output is correct
8 Correct 1081 ms 69592 KB Output is correct
9 Correct 1051 ms 69464 KB Output is correct
10 Correct 1042 ms 69456 KB Output is correct
11 Correct 1056 ms 69456 KB Output is correct
12 Correct 1062 ms 69300 KB Output is correct
13 Correct 1080 ms 69380 KB Output is correct
14 Correct 1053 ms 69556 KB Output is correct
15 Correct 1032 ms 69620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2476 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2460 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2424 KB Output is correct
20 Correct 0 ms 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2476 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2460 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2424 KB Output is correct
20 Correct 0 ms 2392 KB Output is correct
21 Correct 8 ms 11200 KB Output is correct
22 Correct 8 ms 11204 KB Output is correct
23 Correct 8 ms 11100 KB Output is correct
24 Correct 9 ms 11096 KB Output is correct
25 Correct 9 ms 11100 KB Output is correct
26 Correct 9 ms 11100 KB Output is correct
27 Correct 9 ms 11100 KB Output is correct
28 Correct 11 ms 11376 KB Output is correct
29 Correct 9 ms 11096 KB Output is correct
30 Correct 8 ms 11100 KB Output is correct
31 Correct 8 ms 11100 KB Output is correct
32 Correct 8 ms 11216 KB Output is correct
33 Correct 7 ms 11100 KB Output is correct
34 Correct 6 ms 11100 KB Output is correct
35 Correct 6 ms 11100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1029 ms 69188 KB Output is correct
2 Correct 1078 ms 69856 KB Output is correct
3 Correct 1027 ms 69624 KB Output is correct
4 Correct 1055 ms 69380 KB Output is correct
5 Correct 1032 ms 69252 KB Output is correct
6 Correct 1055 ms 69460 KB Output is correct
7 Correct 1045 ms 69364 KB Output is correct
8 Correct 1081 ms 69592 KB Output is correct
9 Correct 1051 ms 69464 KB Output is correct
10 Correct 1042 ms 69456 KB Output is correct
11 Correct 1056 ms 69456 KB Output is correct
12 Correct 1062 ms 69300 KB Output is correct
13 Correct 1080 ms 69380 KB Output is correct
14 Correct 1053 ms 69556 KB Output is correct
15 Correct 1032 ms 69620 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2476 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2460 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 0 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 1 ms 2424 KB Output is correct
35 Correct 0 ms 2392 KB Output is correct
36 Correct 8 ms 11200 KB Output is correct
37 Correct 8 ms 11204 KB Output is correct
38 Correct 8 ms 11100 KB Output is correct
39 Correct 9 ms 11096 KB Output is correct
40 Correct 9 ms 11100 KB Output is correct
41 Correct 9 ms 11100 KB Output is correct
42 Correct 9 ms 11100 KB Output is correct
43 Correct 11 ms 11376 KB Output is correct
44 Correct 9 ms 11096 KB Output is correct
45 Correct 8 ms 11100 KB Output is correct
46 Correct 8 ms 11100 KB Output is correct
47 Correct 8 ms 11216 KB Output is correct
48 Correct 7 ms 11100 KB Output is correct
49 Correct 6 ms 11100 KB Output is correct
50 Correct 6 ms 11100 KB Output is correct
51 Correct 1072 ms 69288 KB Output is correct
52 Correct 1048 ms 69180 KB Output is correct
53 Correct 1103 ms 69404 KB Output is correct
54 Correct 1229 ms 70740 KB Output is correct
55 Correct 1215 ms 71264 KB Output is correct
56 Correct 1236 ms 71120 KB Output is correct
57 Correct 1217 ms 71072 KB Output is correct
58 Correct 1209 ms 70836 KB Output is correct
59 Correct 1209 ms 70872 KB Output is correct
60 Correct 1107 ms 71216 KB Output is correct
61 Correct 1102 ms 70808 KB Output is correct
62 Correct 1087 ms 70960 KB Output is correct
63 Correct 696 ms 70956 KB Output is correct
64 Correct 707 ms 70940 KB Output is correct
65 Correct 717 ms 71024 KB Output is correct
66 Correct 797 ms 70928 KB Output is correct
67 Correct 808 ms 71212 KB Output is correct
68 Correct 798 ms 70992 KB Output is correct