Submission #544778

#TimeUsernameProblemLanguageResultExecution timeMemory
544778rainboyPIN (CEOI10_pin)C11
100 / 100
22 ms7308 KiB
#include <ctype.h>
#include <stdio.h>

#define N	50000
#define K	4
#define B	36
#define A	(B * B * B * B)

int code(char *cc, int b) {
	int h, a;
	
	a = 0;
	for (h = 0; h < K; h++)
		a = a * B + ((b & 1 << h) != 0 ? cc[h] : 0);
	return a;
}

int count(int b) {
	return b == 0 ? 0 : count(b & b - 1) + 1;
}

int main() {
	static char cc[N][K + 1];
	static int cnt[A];
	static long long kk[1 << K];
	int n, m, h, i, b, ans;

	scanf("%d%d", &n, &m), m = 4 - m;
	for (i = 0; i < n; i++) {
		scanf("%s", cc[i]);
		for (h = 0; h < K; h++)
			cc[i][h] = isdigit(cc[i][h]) ? cc[i][h] - '0' : cc[i][h] - 'a' + 10;
	}
	for (b = 0; b < 1 << K; b++) {
		for (i = 0; i < n; i++)
			kk[b] += cnt[code(cc[i], b)]++;
		for (i = 0; i < n; i++)
			cnt[code(cc[i], b)]--;
	}
	for (h = 0; h < K; h++)
		for (b = 0; b < 1 << K; b++)
			if ((b & 1 << h) == 0)
				kk[b] -= kk[b | 1 << h];
	ans = 0;
	for (b = 0; b < 1 << K; b++)
		if (count(b) == m)
			ans += kk[b];
	printf("%d\n", ans);
	return 0;
}

Compilation message (stderr)

pin.c: In function 'count':
pin.c:19:34: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   19 |  return b == 0 ? 0 : count(b & b - 1) + 1;
      |                                ~~^~~
pin.c: In function 'main':
pin.c:28:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |  scanf("%d%d", &n, &m), m = 4 - m;
      |  ^~~~~~~~~~~~~~~~~~~~~
pin.c:30:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |   scanf("%s", cc[i]);
      |   ^~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...