Submission #544735

#TimeUsernameProblemLanguageResultExecution timeMemory
544735rainboyPlus Minus (BOI17_plusminus)C11
100 / 100
64 ms3608 KiB
#include <stdio.h>

#define N	100000
#define MD	1000000007

unsigned int X = 12345;

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

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

int compare_x(const void *a, const void *b) {
	int i = *(int *) a;
	int j = *(int *) b;

	return xx[i] - xx[j];
}

int compare_y(const void *a, const void *b) {
	int i = *(int *) a;
	int j = *(int *) b;

	return yy[i] - yy[j];
}

int (*compare)(const void *, const void *);

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

long long power(int a, int k) {
	long long b = a, p = 1;

	while (k) {
		if (k & 1)
			p = p * b % MD;
		b = b * b % MD;
		k >>= 1;
	}
	return p;
}

int main() {
	static int ii[N];
	int n, x_, y_, i, j, extra, cnt, ans;

	scanf("%d%d%d", &x_, &y_, &n);
	extra = 1;
	for (i = 0; i < n; i++) {
		static char s[2];

		scanf("%s%d%d", s, &xx[i], &yy[i]);
		cc[i] = s[0];
		if (((xx[i] + yy[i]) % 2 == (xx[0] + yy[0]) % 2) != (cc[i] == cc[0]))
			extra = 0;
		ii[i] = i;
	}
	ans = 0;
	compare = compare_x, sort(ii, 0, n);
	cnt = x_;
	for (i = 0; i < n; i = j) {
		int x = xx[ii[i]];

		j = i + 1;
		while (j < n && xx[ii[j]] == x) {
			if ((yy[ii[i]] % 2 == yy[ii[j]] % 2) != (cc[ii[i]] == cc[ii[j]])) {
				cnt = -1;
				goto outx;
			}
			j++;
		}
		cnt--;
	}
outx:
	if (cnt >= 0)
		ans = (ans + power(2, cnt)) % MD;
	compare = compare_y, sort(ii, 0, n);
	cnt = y_;
	for (i = 0; i < n; i = j) {
		int y = yy[ii[i]];

		j = i + 1;
		while (j < n && yy[ii[j]] == y) {
			if ((xx[ii[i]] % 2 == xx[ii[j]] % 2) != (cc[ii[i]] == cc[ii[j]])) {
				cnt = -1;
				goto outy;
			}
			j++;
		}
		cnt--;
	}
outy:
	if (cnt >= 0)
		ans = (ans + power(2, cnt)) % MD;
	if (extra)
		ans = (ans - (n > 0 ? 1 : 2) + MD) % MD;
	printf("%d\n", ans);
	return 0;
}

Compilation message (stderr)

plusminus.c: In function 'main':
plusminus.c:68:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |  scanf("%d%d%d", &x_, &y_, &n);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
plusminus.c:73:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |   scanf("%s%d%d", s, &xx[i], &yy[i]);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...