답안 #484596

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
484596 2021-11-04T14:54:42 Z rainboy Geometrija (COCI21_geometrija) C
110 / 110
639 ms 344 KB
#include <stdio.h>

#define N	1000

unsigned int X = 12345;

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

long long cross2(int x1, int y1, int x2, int y2) {
	return (long long) x1 * y2 - (long long) x2 * y1;
}

int xx[N], yy[N], n, o;

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

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 intersect(int i, int j, int k, int l) {
	return (cross(i, j, k) > 0) != (cross(i, j, l) > 0) && (cross(k, l, i) > 0) != (cross(k, l, j) > 0);
}

int good(int i, int j) {
	static int kk[N], ll[N];
	int nk, nl, k, l, l_;

	nk = 0, nl = 0;
	for (k = 0; k < n; k++)
		if (k != i && k != j) {
			if (cross(i, j, k) > 0)
				kk[nk++] = k;
			else
				ll[nl++] = k;
		}
	o = i, sort(kk, 0, nk), sort(ll, 0, nl);
	for (k = 0, l = 0, l_ = -1; k < nk; k++) {
		while (l < nl && cross(i, kk[k], ll[l]) < 0) {
			if (l_ == -1 || cross(j, l_, ll[l]) < 0)
				l_ = ll[l];
			l++;
		}
		if (l_ != -1 && cross(j, l_, kk[k]) < 0)
			return 0;
	}
	return 1;
}

int main() {
	static int ii[N], uu[N * 3], vv[N * 3], ww[N * 3];
	static char hull[N];
	int m, h, i, cnt;

	scanf("%d", &n);
	o = -1;
	for (i = 0; i < n; i++) {
		scanf("%d%d", &xx[i], &yy[i]);
		if (o == -1 || xx[o] > xx[i] || xx[o] == xx[i] && yy[o] > yy[i])
			o = i;
		ii[i] = i;
	}
	ii[0] = o, ii[o] = 0;
	sort(ii, 1, n);
	m = 0;
	for (i = 0; i < n; i++) {
		while (m >= 2 && cross(ii[m - 2], ii[m - 1], ii[i]) >= 0)
			m--;
		ii[m++] = ii[i];
	}
	cnt = m;
	for (h = 0; h < m; h++)
		hull[ii[h]] = 1;
	for (h = 0; h + 2 < m; h++)
		uu[h] = ii[0], vv[h] = ii[h + 1], ww[h] = ii[h + 2];
	m -= 2;
	for (i = 0; i < n; i++)
		if (!hull[i]) {
			for (h = 0; h < m; h++) {
				int u = uu[h], v = vv[h], w = ww[h];

				if (cross(i, u, v) < 0 && cross(i, v, w) < 0 && cross(i, w, u) < 0) {
					while (h + 1 < m)
						uu[h] = uu[h + 1], vv[h] = vv[h + 1], ww[h] = ww[h + 1], h++;
					m--;
					uu[m] = i, vv[m] = u, ww[m] = v, m++;
					uu[m] = i, vv[m] = v, ww[m] = w, m++;
					uu[m] = i, vv[m] = w, ww[m] = u, m++;
				}
			}
		}
	for (h = 0; h < m; h++) {
		int u = uu[h], v = vv[h], w = ww[h];

		if (good(u, v))
			cnt++;
		if (good(v, w))
			cnt++;
		if (good(w, u))
			cnt++;
	}
	cnt /= 2;
	printf("%d\n", cnt);
	return 0;
}

Compilation message

geometrija.c: In function 'main':
geometrija.c:81:50: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   81 |   if (o == -1 || xx[o] > xx[i] || xx[o] == xx[i] && yy[o] > yy[i])
      |                                   ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
geometrija.c:77:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   77 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
geometrija.c:80:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   80 |   scanf("%d%d", &xx[i], &yy[i]);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 19 ms 308 KB Output is correct
13 Correct 20 ms 204 KB Output is correct
14 Correct 15 ms 308 KB Output is correct
15 Correct 14 ms 312 KB Output is correct
16 Correct 10 ms 312 KB Output is correct
17 Correct 18 ms 204 KB Output is correct
18 Correct 19 ms 308 KB Output is correct
19 Correct 21 ms 308 KB Output is correct
20 Correct 21 ms 204 KB Output is correct
21 Correct 21 ms 316 KB Output is correct
22 Correct 19 ms 308 KB Output is correct
23 Correct 20 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 19 ms 308 KB Output is correct
13 Correct 20 ms 204 KB Output is correct
14 Correct 15 ms 308 KB Output is correct
15 Correct 14 ms 312 KB Output is correct
16 Correct 10 ms 312 KB Output is correct
17 Correct 18 ms 204 KB Output is correct
18 Correct 19 ms 308 KB Output is correct
19 Correct 21 ms 308 KB Output is correct
20 Correct 21 ms 204 KB Output is correct
21 Correct 21 ms 316 KB Output is correct
22 Correct 19 ms 308 KB Output is correct
23 Correct 20 ms 204 KB Output is correct
24 Correct 630 ms 324 KB Output is correct
25 Correct 603 ms 320 KB Output is correct
26 Correct 604 ms 204 KB Output is correct
27 Correct 609 ms 308 KB Output is correct
28 Correct 603 ms 324 KB Output is correct
29 Correct 409 ms 300 KB Output is correct
30 Correct 425 ms 300 KB Output is correct
31 Correct 308 ms 204 KB Output is correct
32 Correct 306 ms 336 KB Output is correct
33 Correct 487 ms 332 KB Output is correct
34 Correct 500 ms 344 KB Output is correct
35 Correct 598 ms 328 KB Output is correct
36 Correct 621 ms 328 KB Output is correct
37 Correct 639 ms 332 KB Output is correct
38 Correct 638 ms 336 KB Output is correct
39 Correct 616 ms 332 KB Output is correct
40 Correct 610 ms 332 KB Output is correct
41 Correct 611 ms 336 KB Output is correct
42 Correct 612 ms 332 KB Output is correct