Submission #484595

# Submission time Handle Problem Language Result Execution time Memory
484595 2021-11-04T14:46:03 Z rainboy Geometrija (COCI21_geometrija) C
50 / 110
1000 ms 332 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) {
	int k, l;

	for (k = 0; k < n; k++)
		for (l = k + 1; l < n; l++)
			if (k != i && k != j && l != i && l != j && intersect(i, j, k, l))
				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:66:50: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   66 |   if (o == -1 || xx[o] > xx[i] || xx[o] == xx[i] && yy[o] > yy[i])
      |                                   ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
geometrija.c:62:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
geometrija.c:65:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |   scanf("%d%d", &xx[i], &yy[i]);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 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 280 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 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 280 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 12 ms 312 KB Output is correct
13 Correct 9 ms 284 KB Output is correct
14 Correct 6 ms 204 KB Output is correct
15 Correct 6 ms 304 KB Output is correct
16 Correct 20 ms 296 KB Output is correct
17 Correct 24 ms 312 KB Output is correct
18 Correct 16 ms 204 KB Output is correct
19 Correct 22 ms 308 KB Output is correct
20 Correct 127 ms 284 KB Output is correct
21 Correct 104 ms 288 KB Output is correct
22 Correct 13 ms 280 KB Output is correct
23 Correct 15 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 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 280 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 12 ms 312 KB Output is correct
13 Correct 9 ms 284 KB Output is correct
14 Correct 6 ms 204 KB Output is correct
15 Correct 6 ms 304 KB Output is correct
16 Correct 20 ms 296 KB Output is correct
17 Correct 24 ms 312 KB Output is correct
18 Correct 16 ms 204 KB Output is correct
19 Correct 22 ms 308 KB Output is correct
20 Correct 127 ms 284 KB Output is correct
21 Correct 104 ms 288 KB Output is correct
22 Correct 13 ms 280 KB Output is correct
23 Correct 15 ms 204 KB Output is correct
24 Correct 277 ms 332 KB Output is correct
25 Correct 161 ms 332 KB Output is correct
26 Correct 252 ms 332 KB Output is correct
27 Correct 289 ms 332 KB Output is correct
28 Correct 240 ms 332 KB Output is correct
29 Correct 141 ms 204 KB Output is correct
30 Correct 155 ms 304 KB Output is correct
31 Execution timed out 1095 ms 204 KB Time limit exceeded
32 Halted 0 ms 0 KB -