답안 #544768

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
544768 2022-04-02T16:36:15 Z rainboy Dominance (CEOI08_dominance) C
100 / 100
12 ms 380 KB
#include <stdio.h>

#define N	3000

unsigned int X = 12345;

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

int *zz;

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 (zz[ii[j]] == zz[i_])
				j++;
			else if (zz[ii[j]] < zz[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;
	}
}

long long count(int x1, int x2, int y1, int y2) {
	return (long long) (x2 - x1) * (y2 - y1) / 2 + ((x2 - x1) % 2 != 0 && (y2 - y1) % 2 != 0 && (x1 + y1) % 2 == 0);
}

int main() {
	static int xx[N * 2], yy[N * 2], yy1[N * 2], yy_[N * 2], rr[N], cc[N], ii[N * 2], dd[N * 2];
	int n, w, h, i, j;
	long long ans1, ans2;

	scanf("%d%d%d", &w, &h, &n);
	for (i = 0; i < n; i++) {
		static char s[2];
		int x, y;

		scanf("%s%d%d%d", s, &x, &y, &rr[i]);
		cc[i] = s[0] == 'W' ? 1 : -1;
		xx[i << 1 | 0] = x + y - rr[i], xx[i << 1 | 1] = x + y + rr[i] + 1;
		yy[i << 1 | 0] = x - y - rr[i], yy[i << 1 | 1] = x - y + rr[i] + 1;
	}
	for (i = 0; i < n * 2; i++)
		ii[i] = i;
	zz = yy, sort(ii, 0, n * 2);
	for (i = 0; i < n * 2; i++)
		yy1[i] = yy[ii[i]], yy_[ii[i]] = i;
	zz = xx, sort(ii, 0, n * 2);
	ans1 = ans2 = 0;
	for (i = 0; i + 1 < n * 2; i++) {
		int i_ = ii[i] >> 1, c = cc[i_] * ((ii[i] & 1) == 0 ? 1 : -1), d;

		dd[yy_[i_ << 1 | 0]] += c;
		dd[yy_[i_ << 1 | 1]] -= c;
		d = 0;
		for (j = 0; j + 1 < n * 2; j++) {
			d += dd[j];
			if (d > 0)
				ans1 += count(xx[ii[i]], xx[ii[i + 1]], yy1[j], yy1[j + 1]);
			else if (d < 0)
				ans2 += count(xx[ii[i]], xx[ii[i + 1]], yy1[j], yy1[j + 1]);
		}
	}
	printf("%lld\n", ans1);
	printf("%lld\n", ans2);
	return 0;
}

Compilation message

dominance.c: In function 'main':
dominance.c:41:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |  scanf("%d%d%d", &w, &h, &n);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~
dominance.c:46:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |   scanf("%s%d%d%d", s, &x, &y, &rr[i]);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 4 ms 340 KB Output is correct
5 Correct 5 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 3 ms 340 KB Output is correct
9 Correct 6 ms 340 KB Output is correct
10 Correct 6 ms 340 KB Output is correct
11 Correct 7 ms 340 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 6 ms 340 KB Output is correct
14 Correct 0 ms 292 KB Output is correct
15 Correct 12 ms 340 KB Output is correct
16 Correct 9 ms 380 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 3 ms 340 KB Output is correct
20 Correct 2 ms 340 KB Output is correct