#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const int MAXN = 27 * 27 * 27 * 27;
int N;
int cnt[MAXN][16]; // NESW
inline int Hash(int c[2][2]) {
return c[0][0] * 27 * 27 * 27 +
c[0][1] * 27 * 27 +
c[1][0] * 27 +
c[1][1];
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> N;
lint ans = 0;
for (int cards = 0; cards < N; cards++) {
int c[2][2];
int alt[2][2];
int pick[2][2];
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
char a;
cin >> a;
c[i][j] = a - 'A' + 1;
}
}
for (int mask = 1; mask < 16; mask++) {
alt[0][0] = alt[0][1] = alt[1][0] = alt[1][1] = 0;
pick[0][0] = pick[0][1] = pick[1][0] = pick[1][1] = 0;
int cur = 0;
if (mask & (1 << 0)) { // N
alt[0][0] |= 1 << (c[1][0]);
alt[0][1] |= 1 << (c[1][1]);
pick[0][0] |= c[1][0];
pick[0][1] |= c[1][1];
}
if (mask & (1 << 1)) { // E
alt[0][1] |= 1 << (c[0][0]);
alt[1][1] |= 1 << (c[1][0]);
pick[0][1] |= c[0][0];
pick[1][1] |= c[1][0];
}
if (mask & (1 << 2)) { // S
alt[1][0] |= 1 << (c[0][0]);
alt[1][1] |= 1 << (c[0][1]);
pick[1][0] |= c[0][0];
pick[1][1] |= c[0][1];
}
if (mask & (1 << 3)) { // W
alt[0][0] |= 1 << (c[0][1]);
alt[1][0] |= 1 << (c[1][1]);
pick[0][0] |= c[0][1];
pick[1][0] |= c[1][1];
}
int can = 1;
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
if (alt[i][j] & (alt[i][j] - 1)) {
can = 0;
}
}
}
if (can) {
cur = cnt[Hash(pick)][mask];
}
ans += cur;
}
for (int mask = 1; mask < 16; mask++) {
pick[0][0] = pick[0][1] = pick[1][0] = pick[1][1] = 0;
if (mask & (1 << 0)) { // N
pick[0][0] = c[0][0];
pick[0][1] = c[0][1];
}
if (mask & (1 << 1)) { // E
pick[0][1] = c[0][1];
pick[1][1] = c[1][1];
}
if (mask & (1 << 2)) { // S
pick[1][0] = c[1][0];
pick[1][1] = c[1][1];
}
if (mask & (1 << 3)) { // W
pick[0][0] = c[0][0];
pick[1][0] = c[1][0];
}
if (__builtin_popcount(mask) & 1) {
cnt[Hash(pick)][mask]++;
} else {
cnt[Hash(pick)][mask]--;
}
}
}
cout << ans << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
896 KB |
Output is correct |
4 |
Correct |
2 ms |
1152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
7168 KB |
Output is correct |
3 |
Correct |
3 ms |
2432 KB |
Output is correct |
4 |
Correct |
17 ms |
15232 KB |
Output is correct |
5 |
Correct |
10 ms |
8832 KB |
Output is correct |
6 |
Correct |
9 ms |
9856 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
896 KB |
Output is correct |
11 |
Correct |
2 ms |
1152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
333 ms |
33664 KB |
Output is correct |
2 |
Correct |
333 ms |
33656 KB |
Output is correct |
3 |
Correct |
355 ms |
33656 KB |
Output is correct |
4 |
Correct |
334 ms |
33660 KB |
Output is correct |
5 |
Correct |
357 ms |
33656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
58 ms |
32504 KB |
Output is correct |
3 |
Correct |
233 ms |
32504 KB |
Output is correct |
4 |
Correct |
136 ms |
32576 KB |
Output is correct |
5 |
Correct |
146 ms |
32636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
7168 KB |
Output is correct |
3 |
Correct |
3 ms |
2432 KB |
Output is correct |
4 |
Correct |
17 ms |
15232 KB |
Output is correct |
5 |
Correct |
10 ms |
8832 KB |
Output is correct |
6 |
Correct |
9 ms |
9856 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
896 KB |
Output is correct |
11 |
Correct |
2 ms |
1152 KB |
Output is correct |
12 |
Correct |
333 ms |
33664 KB |
Output is correct |
13 |
Correct |
333 ms |
33656 KB |
Output is correct |
14 |
Correct |
355 ms |
33656 KB |
Output is correct |
15 |
Correct |
334 ms |
33660 KB |
Output is correct |
16 |
Correct |
357 ms |
33656 KB |
Output is correct |
17 |
Correct |
58 ms |
32504 KB |
Output is correct |
18 |
Correct |
233 ms |
32504 KB |
Output is correct |
19 |
Correct |
136 ms |
32576 KB |
Output is correct |
20 |
Correct |
146 ms |
32636 KB |
Output is correct |
21 |
Correct |
90 ms |
33656 KB |
Output is correct |
22 |
Correct |
274 ms |
33656 KB |
Output is correct |
23 |
Correct |
183 ms |
33656 KB |
Output is correct |
24 |
Correct |
227 ms |
33656 KB |
Output is correct |