Submission #508835

# Submission time Handle Problem Language Result Execution time Memory
508835 2022-01-13T21:27:07 Z rainboy None (JOI12_constellation) C
100 / 100
53 ms 4008 KB
/* https://ioi.te.lv/locations/ioi06/contest/day2/points/points_sol.pdf */
#include <stdio.h>

#define N	100000
#define MD	1000000007

unsigned int X = 12345;

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

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

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]);
}

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;
	}
}

long long solve(int *ii, int n, int c) {
	int i, j, l, l_, r, r_;
	long long ans;

	l_ = 0;
	while (l_ < n && cc[ii[l_]] != c)
		l_++;
	r_ = n - 1;
	while (r_ >= 0 && cc[ii[r_]] != c)
		r_--;
	if (l_ == 0)
		return 0;
	if (l_ == n) {
		ans = 1;
		for (i = 0, j = 1; j <= n; j++)
			if (j == n || cc[ii[j]] == (c ^ 1)) {
				ans += (long long) (j - i) * (j - i - 1) / 2;
				i = j;
			}
		return ans;
	} else {
		for (i = l_; i <= r_; i++)
			if (cc[ii[i]] == (c ^ 1))
				return 0;
		l = l_;
		while (l > 0 && cc[ii[l]] != (c ^ 1))
			l--;
		r = r_;
		while (r < n && cc[ii[r]] != (c ^ 1))
			r++;
		return (long long) (l_ - l) * (r - r_);
	}
}

int main() {
	static int ii[N];
	static char hull[N];
	int n, cnt, h, i, ans;

	scanf("%d", &n);
	o = -1;
	for (i = 0; i < n; i++) {
		scanf("%d%d%d", &xx[i], &yy[i], &cc[i]), cc[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);
	cnt = 0;
	for (i = 0; i < n; i++) {
		while (cnt >= 2 && cross(ii[cnt - 2], ii[cnt - 1], ii[i]) >= 0)
			cnt--;
		ii[cnt++] = ii[i];
	}
	for (h = 0; h < cnt; h++)
		hull[ii[h]] = 1;
	ans = (solve(ii, cnt, 0) + solve(ii, cnt, 1)) % MD;
	for (i = 0; i < n; i++)
		if (!hull[i] && cc[i] == -1)
			ans = ans * 2 % MD;
	ans = (ans - 2 + MD) % MD;
	for (i = 0; i < n; i++)
		if (cc[i] == 1) {
			ans = (ans + 1) % MD;
			break;
		}
	for (i = 0; i < n; i++)
		if (cc[i] == 0) {
			ans = (ans + 1) % MD;
			break;
		}
	printf("%d\n", ans);
	return 0;
}

Compilation message

constellation.c: In function 'main':
constellation.c:84:50: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   84 |   if (o == -1 || xx[o] > xx[i] || xx[o] == xx[i] && yy[o] > yy[i])
      |                                   ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
constellation.c:80:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   80 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
constellation.c:83:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   83 |   scanf("%d%d%d", &xx[i], &yy[i], &cc[i]), cc[i]--;
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 272 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 284 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 280 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 284 KB Output is correct
4 Correct 1 ms 300 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 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 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 284 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 0 ms 204 KB Output is correct
6 Correct 0 ms 300 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 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 2 ms 460 KB Output is correct
3 Correct 3 ms 424 KB Output is correct
4 Correct 3 ms 460 KB Output is correct
5 Correct 3 ms 420 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 2 ms 424 KB Output is correct
8 Correct 2 ms 460 KB Output is correct
9 Correct 2 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 49 ms 3924 KB Output is correct
3 Correct 1 ms 284 KB Output is correct
4 Correct 50 ms 3952 KB Output is correct
5 Correct 45 ms 3936 KB Output is correct
6 Correct 1 ms 272 KB Output is correct
7 Correct 2 ms 400 KB Output is correct
8 Correct 2 ms 460 KB Output is correct
9 Correct 3 ms 404 KB Output is correct
10 Correct 46 ms 3964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 48 ms 3972 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 50 ms 3912 KB Output is correct
5 Correct 44 ms 3872 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 2 ms 420 KB Output is correct
8 Correct 2 ms 420 KB Output is correct
9 Correct 2 ms 424 KB Output is correct
10 Correct 46 ms 3860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 53 ms 3992 KB Output is correct
3 Correct 47 ms 3856 KB Output is correct
4 Correct 48 ms 3924 KB Output is correct
5 Correct 44 ms 3900 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 3 ms 460 KB Output is correct
8 Correct 2 ms 420 KB Output is correct
9 Correct 3 ms 456 KB Output is correct
10 Correct 46 ms 3836 KB Output is correct
11 Correct 45 ms 3884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 49 ms 4008 KB Output is correct
3 Correct 48 ms 3952 KB Output is correct
4 Correct 46 ms 3936 KB Output is correct
5 Correct 47 ms 3848 KB Output is correct
6 Correct 48 ms 3944 KB Output is correct
7 Correct 3 ms 460 KB Output is correct
8 Correct 3 ms 460 KB Output is correct
9 Correct 3 ms 460 KB Output is correct
10 Correct 18 ms 2000 KB Output is correct