Submission #503334

#TimeUsernameProblemLanguageResultExecution timeMemory
503334rainboyKućice (COCI21_kucice)C11
110 / 110
157 ms300 KiB
#include <stdio.h>

#define N	1000
#define MD	1000000007

unsigned int X = 12345;

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

int pp2[N + 1];

void init() {
	int i;

	pp2[0] = 1;
	for (i = 1; i <= N; i++)
		pp2[i] = pp2[i - 1] * 2 % MD;
}

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;

int compare(int i, int j) {
	int sgni = xx[i] < xx[o] || xx[i] == xx[o] && yy[i] < yy[o] ? -1 : 1;
	int sgnj = xx[j] < xx[o] || xx[j] == xx[o] && yy[j] < yy[o] ? -1 : 1;
	long long c;

	if (sgni != sgnj)
		return sgni - sgnj;
	c = cross(o, i, j);
	return c == 0 ? 0 : (c < 0 ? -1 : 1);
}

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) {
			int c = compare(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 ii[N];
	int n, i, j, k, ans;

	init();
	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%d%d", &xx[i], &yy[i]);
	ans = (long long) (pp2[n] - 1) * n % MD;
	if (n > 1)
		for (i = 0; i < n; i++) {
			for (j = 0; j < n; j++)
				if (j != i)
					ii[j < i ? j : j - 1] = j;
			o = i, sort(ii, 0, n - 1);
			for (j = 0, k = 0; j < n - 1; j++) {
				while (k < n - 1 + j && cross(i, ii[j], ii[k % (n - 1)]) <= 0)
					k++;
				ans = (ans - pp2[k - 1 - j] + MD) % MD;
			}
		}
	printf("%d\n", ans);
	return 0;
}

Compilation message (stderr)

Main.c: In function 'compare':
Main.c:31:45: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   31 |  int sgni = xx[i] < xx[o] || xx[i] == xx[o] && yy[i] < yy[o] ? -1 : 1;
      |                              ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
Main.c:32:45: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   32 |  int sgnj = xx[j] < xx[o] || xx[j] == xx[o] && yy[j] < yy[o] ? -1 : 1;
      |                              ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
Main.c: In function 'main':
Main.c:68:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
Main.c:70:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |   scanf("%d%d", &xx[i], &yy[i]);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...