Submission #545165

# Submission time Handle Problem Language Result Execution time Memory
545165 2022-04-03T17:56:45 Z rainboy Question (Grader is different from the original contest) (CEOI14_question_grader) C
100 / 100
3114 ms 24220 KB
#define L	12
#define N	924	/* N = choose(L, L / 2) */

static int cnt[1 << L], bb[N], n, inited = 0;

void init() {
	if (!inited) {
		int b;

		n = 0;
		cnt[0] = 0;
		for (b = 1; b < 1 << L; b++)
			if ((cnt[b] = cnt[b & b - 1] + 1) == L / 2)
				bb[n++] = b;
		inited = 1;
	}
}

int encode(int n, int x, int y) {
	int l;

	init();
	x--, y--;
	for (l = 0; l < L; l++)
		if ((bb[x] & 1 << l) == 0 && (bb[y] & 1 << l) != 0)
			return l + 1;
	return 0;
}
#define L	12
#define N	924	/* N = choose(L, L / 2) */

static int cnt[1 << L], bb[N], n, inited = 0;

void init() {
	if (!inited) {
		int b;

		n = 0;
		cnt[0] = 0;
		for (b = 1; b < 1 << L; b++)
			if ((cnt[b] = cnt[b & b - 1] + 1) == L / 2)
				bb[n++] = b;
		inited = 1;
	}
}

int decode(int n, int x, int y) {
	init();
	x--, y--;
	return (bb[x] & 1 << y) == 0;
}

Compilation message

encoder.c: In function 'init':
encoder.c:13:28: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   13 |    if ((cnt[b] = cnt[b & b - 1] + 1) == L / 2)
      |                          ~~^~~

decoder.c: In function 'init':
decoder.c:13:28: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   13 |    if ((cnt[b] = cnt[b & b - 1] + 1) == L / 2)
      |                          ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 3114 ms 24076 KB Output is correct - maxh = 12
2 Correct 2969 ms 24220 KB Output is correct - maxh = 12