Submission #875939

#TimeUsernameProblemLanguageResultExecution timeMemory
875939rainboyCards (LMIO19_korteles)C11
100 / 100
77 ms5152 KiB
#include <stdio.h>

#define A	26
#define M	531441	/* M = (A + 1)^4 */

int idx(int a, int b, int c, int d) {
	return ((a * (A + 1) + b) * (A + 1) + c) * (A + 1) + d;
}

int main() {
	static int kk[M];
	int n, a, b, c, d, e, f, g, h, u, w;
	long long ans;

	scanf("%d", &n);
	while (n--) {
		static char s[4], t[4];
		int u;

		scanf("%s%s", s, t);
		a = s[0] - 'A' + 1, b = s[1] - 'A' + 1;
		c = t[0] - 'A' + 1, d = t[1] - 'A' + 1;
		for (u = 0; u < 16; u++)
			kk[idx((u & 1) != 0 ? a : 0, (u & 2) != 0 ? b : 0, (u & 4) != 0 ? c : 0, (u & 8) != 0 ? d : 0)]++;
	}
	ans = 0;
	for (a = 1; a <= A; a++)
		for (b = 1; b <= A; b++)
			for (c = 1; c <= A; c++)
				for (d = 1; d <= A; d++)
					if (kk[idx(a, b, c, d)] > 0) {
						for (u = 1; u < 16; u++) {
							e = 0, f = 0;
							g = 0, h = 0;
							w = -1;
							if ((u & 1) != 0) {
								if (e == 0 || e == c)
									e = c;
								else
									continue;
								if (f == 0 || f == d)
									f = d;
								else
									continue;
								w = -w;
							}
							if ((u & 2) != 0) {
								if (g == 0 || g == a)
									g = a;
								else
									continue;
								if (h == 0 || h == b)
									h = b;
								else
									continue;
								w = -w;
							}
							if ((u & 4) != 0) {
								if (e == 0 || e == b)
									e = b;
								else
									continue;
								if (g == 0 || g == d)
									g = d;
								else
									continue;
								w = -w;
							}
							if ((u & 8) != 0) {
								if (f == 0 || f == a)
									f = a;
								else
									continue;
								if (h == 0 || h == c)
									h = c;
								else
									continue;
								w = -w;
							}
							ans += kk[idx(e, f, g, h)] * w;
						}
						if (a == c && b == d || a == b && c == d)
							ans--;
					}
	ans /= 2;
	printf("%lld\n", ans);
	return 0;
}

Compilation message (stderr)

korteles.c: In function 'main':
korteles.c:82:18: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   82 |       if (a == c && b == d || a == b && c == d)
      |           ~~~~~~~^~~~~~~~~
korteles.c:15:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
korteles.c:20:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |   scanf("%s%s", s, t);
      |   ^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...