Submission #484285

# Submission time Handle Problem Language Result Execution time Memory
484285 2021-11-02T20:44:52 Z rainboy Planine (COCI21_planine) C
0 / 110
3 ms 588 KB
#include <stdio.h>

#define N	1000000

unsigned int X = 12345;

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

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

long long pp[N], qq[N];

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(pp[ii[j]], qq[ii[j]], pp[i_], qq[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 xx[N], yy[N], ii[N];
	int n, y, i, p, q, k;

	scanf("%d%d", &n, &y);
	for (i = 0; i < n; i++)
		scanf("%d%d", &xx[i], &yy[i]);
	for (i = 2; i < n - 1; i += 2) {
		pp[i] = cross(xx[i - 1], yy[i - 1] - y, xx[i] - xx[i - 1], yy[i] - yy[i - 1]);
		qq[i] = cross(1, 0, xx[i] - xx[i - 1], yy[i] - yy[i - 1]);
		if (qq[i] < 0)
			pp[i] = -pp[i], qq[i] = -qq[i];
		pp[i + 1] = cross(xx[i + 1], yy[i + 1] - y, xx[i] - xx[i + 1], yy[i] - yy[i + 1]);
		qq[i + 1] = cross(1, 0, xx[i] - xx[i + 1], yy[i] - yy[i + 1]);
		if (qq[i + 1] < 0)
			pp[i + 1] = -pp[i + 1], qq[i + 1] = -qq[i + 1];
		ii[i / 2 - 1] = i + 1;
	}
	sort(ii, 0, n / 2 - 1);
	p = -1, q = 0, k = 0;
	for (i = 0; i < n / 2 - 1; i++)
		if (cross(p, q, pp[ii[i] - 1], qq[ii[i] - 1]) < 0)
			p = pp[ii[i]], q = qq[ii[i]], k++;
	printf("%d\n", k);
	return 0;
}

Compilation message

Main.c: In function 'main':
Main.c:43:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |  scanf("%d%d", &n, &y);
      |  ^~~~~~~~~~~~~~~~~~~~~
Main.c:45:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |   scanf("%d%d", &xx[i], &yy[i]);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 588 KB Output is correct
2 Incorrect 3 ms 588 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 588 KB Output is correct
2 Incorrect 3 ms 588 KB Output isn't correct
3 Halted 0 ms 0 KB -