Submission #875939

# Submission time Handle Problem Language Result Execution time Memory
875939 2023-11-20T19:34:24 Z rainboy Cards (LMIO19_korteles) C
100 / 100
77 ms 5152 KB
#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

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 time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 1884 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 2 ms 2396 KB Output is correct
9 Correct 2 ms 1884 KB Output is correct
10 Correct 2 ms 2140 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 72 ms 5036 KB Output is correct
2 Correct 75 ms 4900 KB Output is correct
3 Correct 73 ms 4908 KB Output is correct
4 Correct 77 ms 5152 KB Output is correct
5 Correct 72 ms 5144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 10 ms 2648 KB Output is correct
3 Correct 50 ms 4180 KB Output is correct
4 Correct 31 ms 3376 KB Output is correct
5 Correct 31 ms 3412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 2 ms 2396 KB Output is correct
5 Correct 2 ms 1884 KB Output is correct
6 Correct 2 ms 2140 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 72 ms 5036 KB Output is correct
13 Correct 75 ms 4900 KB Output is correct
14 Correct 73 ms 4908 KB Output is correct
15 Correct 77 ms 5152 KB Output is correct
16 Correct 72 ms 5144 KB Output is correct
17 Correct 10 ms 2648 KB Output is correct
18 Correct 50 ms 4180 KB Output is correct
19 Correct 31 ms 3376 KB Output is correct
20 Correct 31 ms 3412 KB Output is correct
21 Correct 18 ms 2908 KB Output is correct
22 Correct 57 ms 4508 KB Output is correct
23 Correct 38 ms 3760 KB Output is correct
24 Correct 43 ms 3828 KB Output is correct