Submission #944411

# Submission time Handle Problem Language Result Execution time Memory
944411 2024-03-12T17:17:19 Z rainboy 개구리 (KOI13_frog) C
2.64 / 22
33 ms 2640 KB
#include <stdio.h>
#include <string.h>

#define N	100000

int max(int a, int b) { return a > b ? a : b; }

unsigned int X = 12345;

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

int n, r, d;
int xx[N], yy[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 (xx[ii[j]] == xx[i_])
				j++;
			else if (xx[ii[j]] < xx[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 ds[N];

int find(int i) {
	return ds[i] < 0 ? i : (ds[i] = find(ds[i]));
}

void join(int i, int j) {
	i = find(i);
	j = find(j);
	if (i == j)
		return;
	if (ds[i] > ds[j])
		ds[i] = j;
	else {
		if (ds[i] == ds[j])
			ds[i]--;
		ds[j] = i;
	}
}

int zz[N + 1], ll[N + 1], rr[N + 1], ii[N + 1], _, u_, l_, r_;

int node(int i) {
	zz[_] = rand_();
	ll[_] = rr[_] = 0;
	ii[_] = i;
	return _++;
}

void split(int u, int i) {
	int c;

	if (u == 0) {
		u_ = l_ = r_ = 0;
		return;
	}
	c = yy[ii[u]] != yy[i] ? yy[ii[u]] - yy[i] : ii[u] - i;
	if (c < 0) {
		split(rr[u], i);
		rr[u] = l_, l_ = u;
	} else if (c > 0) {
		split(ll[u], i);
		ll[u] = r_, r_ = u;
	} else {
		u_ = u, l_ = ll[u], r_ = rr[u];
		ll[u] = rr[u] = 0;
	}
}

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 ? ii[u] : first(ll[u]);
}

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

void tr_add(int i) {
	int j;

	split(u_, i);
	if (l_ && yy[i] - yy[j = last(l_)] <= r + d)
		join(i, j);
	if (r_ && yy[j = first(r_)] - yy[i] <= r + d)
		join(i, j);
	u_ = merge(merge(l_, node(i)), r_);
}

void tr_remove(int i) {
	split(u_, i);
	u_ = merge(l_, r_);
}

int main() {
	static int ii[N];
	int h, i, i_, j, tmp, ans;

	scanf("%d%d", &n, &r);
	for (i = 0; i < n; i++)
		scanf("%d%d", &xx[i], &yy[i]);
	scanf("%d", &d);
	memset(ds, -1, n * sizeof *ds);
	for (h = 0; h < 2; h++) {
		for (i = 0; i < n; i++)
			ii[i] = i;
		sort(ii, 0, n);
		_ = 1, u_ = 0;
		for (i = 0, j = 0; i < n; i++) {
			while (j < n && xx[ii[j]] - xx[ii[i]] <= r)
				tr_add(ii[j++]);
			tr_remove(ii[i]);
		}
		for (i = 0; i < n; i++)
			tmp = xx[i], xx[i] = yy[i], yy[i] = tmp;
	}
	i_ = find(0);
	ans = 0;
	for (i = 0; i < n; i++)
		if (find(i) == i_)
			ans = max(ans, xx[i] + yy[i]);
	ans += r * 2;
	printf("%d\n", ans);
	return 0;
}

Compilation message

frog.c: In function 'main':
frog.c:127:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
  127 |  scanf("%d%d", &n, &r);
      |  ^~~~~~~~~~~~~~~~~~~~~
frog.c:129:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
  129 |   scanf("%d%d", &xx[i], &yy[i]);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
frog.c:130:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
  130 |  scanf("%d", &d);
      |  ^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Incorrect 0 ms 344 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 428 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 21 ms 1628 KB Output is correct
2 Incorrect 33 ms 2640 KB Output isn't correct
3 Halted 0 ms 0 KB -