Submission #381192

# Submission time Handle Problem Language Result Execution time Memory
381192 2021-03-24T17:56:40 Z rainboy Circle selection (APIO18_circle_selection) C
7 / 100
208 ms 16108 KB
#include <stdio.h>

#define N	300000

unsigned int X = 12345;

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

int xx[N], yy[N], rr_[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)
			if (rr_[ii[j]] == rr_[i_])
				j++;
			else if (rr_[ii[j]] < rr_[i_]) {
				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 zz[1 + N], ll[1 + N], rr[1 + N], ii_[1 + N], u_, l_, r_;

int node(int i) {
	static int _ = 1;

	zz[_] = rand_();
	ii_[_] = i;
	return _++;
}

void split(int u, int x) {
	int x_;

	if (u == 0) {
		l_ = r_ = 0;
		return;
	}
	x_ = xx[u] - rr[u];
	if (x_ < x) {
		split(rr[u], x);
		rr[u] = l_, l_ = u;
	} else if (x_ > x) {
		split(ll[u], x);
		ll[u] = r_, r_ = u;
	}
}

int merge(int u, int v) {
	if (u == 0)
		return v;
	if (v == 0)
		return u;
	if (zz[u] < zz[v]) {
		rr[u] = merge(rr[u], v);
		return u;
	} else {
		ll[v] = merge(u, ll[v]);
		return v;
	}
}

int first(int u) {
	return ll[u] == 0 ? u : first(ll[u]);
}

int last(int u) {
	return rr[u] == 0 ? u : last(rr[u]);
}

int main() {
	static int ii[N], pp[N];
	static char used[N];
	int n, i;

	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%d%d%d", &xx[i], &yy[i], &rr_[i]);
	if (n <= 5000) {
		while (1) {
			int i_;

			i_ = -1;
			for (i = 0; i < n; i++)
				if (!used[i] && (i_ == -1 || rr_[i_] < rr_[i]))
					i_ = i;
			if (i_ == -1)
				break;
			for (i = 0; i < n; i++) {
				long long x = xx[i] - xx[i_], y = yy[i] - yy[i_], r = rr_[i] + rr_[i_];

				if (!used[i] && x * x + y * y <= r * r)
					used[i] = 1, pp[i] = i_;
			}
		}
	} else {
		for (i = 0; i < n; i++)
			ii[i] = i;
		sort(ii, 0, n);
		for (i = n - 1; i >= 0; i--) {
			int i_ = ii[i], p, q;

			split(u_, xx[i_] - rr_[i_]);
			p = l_ ? ii_[last(l_)] : -1, q = r_ ? ii_[first(r_)] : -1;
			if (p != -1 && xx[p] + rr_[p] < xx[i_] - rr_[i_])
				p = -1;
			if (q != -1 && xx[q] - rr_[q] > xx[i_] - rr_[i_])
				q = -1;
			if (p == -1 && q == -1)
				pp[i_] = i_, u_ = merge(merge(l_, node(i_)), r_);
			else
				pp[i_] = q == -1 || p != -1 && (rr_[p] > rr_[q] || rr_[p] == rr_[q] && p > q) ? p : q;
		}
	}
	for (i = 0; i < n; i++)
		printf("%d ", pp[i] + 1);
	printf("\n");
	return 0;
}

Compilation message

circle_selection.c: In function 'main':
circle_selection.c:122:73: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
  122 |     pp[i_] = q == -1 || p != -1 && (rr_[p] > rr_[q] || rr_[p] == rr_[q] && p > q) ? p : q;
      |                                                        ~~~~~~~~~~~~~~~~~^~~~~~~~
circle_selection.c:122:33: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
  122 |     pp[i_] = q == -1 || p != -1 && (rr_[p] > rr_[q] || rr_[p] == rr_[q] && p > q) ? p : q;
      |                         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
circle_selection.c:86:2: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
   86 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
circle_selection.c:88:3: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
   88 |   scanf("%d%d%d", &xx[i], &yy[i], &rr_[i]);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 372 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 2 ms 364 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 3 ms 620 KB Output is correct
20 Correct 4 ms 620 KB Output is correct
21 Correct 4 ms 620 KB Output is correct
22 Correct 144 ms 620 KB Output is correct
23 Correct 142 ms 612 KB Output is correct
24 Correct 142 ms 620 KB Output is correct
25 Correct 147 ms 620 KB Output is correct
26 Correct 145 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 208 ms 14828 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 75 ms 5772 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 166 ms 16108 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 372 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 2 ms 364 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 3 ms 620 KB Output is correct
20 Correct 4 ms 620 KB Output is correct
21 Correct 4 ms 620 KB Output is correct
22 Correct 144 ms 620 KB Output is correct
23 Correct 142 ms 612 KB Output is correct
24 Correct 142 ms 620 KB Output is correct
25 Correct 147 ms 620 KB Output is correct
26 Correct 145 ms 620 KB Output is correct
27 Incorrect 8 ms 876 KB Output isn't correct
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 372 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 2 ms 364 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 3 ms 620 KB Output is correct
20 Correct 4 ms 620 KB Output is correct
21 Correct 4 ms 620 KB Output is correct
22 Correct 144 ms 620 KB Output is correct
23 Correct 142 ms 612 KB Output is correct
24 Correct 142 ms 620 KB Output is correct
25 Correct 147 ms 620 KB Output is correct
26 Correct 145 ms 620 KB Output is correct
27 Incorrect 208 ms 14828 KB Output isn't correct
28 Halted 0 ms 0 KB -