#include <bits/stdc++.h>
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
typedef long long ll;
const int MAXN = (int)5e5 + 5;
array<int, 2> arr[MAXN][4];
int cnt[16][MAXN];
string str[MAXN];
int mem[MAXN][16];
int n;
int f(char c) {
return c - 'A';
}
bool bit(int x, int p) {
return x & (1 << p);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n;
for (int i = 0; i < n; i++) {
string x, y;
cin >> x >> y;
str[i] = x + y;
arr[i][0] = {0, 1};
arr[i][1] = {0, 2};
arr[i][2] = {1, 3};
arr[i][3] = {2, 3};
for (int mask = 1; mask < 16; mask++) {
vector<int> used(4, 0);
int cur = 0;
for (int j = 0; j < 4; j++) {
if (bit(mask, j)) {
for (int k = 0; k < 2; k++) {
if (!used[arr[i][j][k]]) {
cur = cur * 26 + f(str[i][arr[i][j][k]]);
used[arr[i][j][k]] = 1;
}
}
}
}
mem[i][mask] = cur;
}
}
ll ans = 0;
for (int i = 0; i < n; i++) {
for (int mask = 1; mask < 16; mask++) {
int pp = __builtin_popcount(mask);
if (pp % 2 == 1) {
ans += cnt[mask][mem[i][mask]];
}
else {
ans -= cnt[mask][mem[i][mask]];
}
}
reverse(arr[i], arr[i] + 4);
for (int mask = 1; mask < 16; mask++) {
vector<int> used(4, 0);
int cur = 0;
for (int j = 0; j < 4; j++) {
if (bit(mask, j)) {
for (int k = 0; k < 2; k++) {
if (!used[arr[i][j][k]]) {
cur = cur * 26 + f(str[i][arr[i][j][k]]);
used[arr[i][j][k]] = 1;
}
}
}
}
cnt[mask][cur]++;
}
}
cout << ans << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
16076 KB |
Output is correct |
2 |
Correct |
8 ms |
16460 KB |
Output is correct |
3 |
Correct |
9 ms |
16972 KB |
Output is correct |
4 |
Correct |
9 ms |
17448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
16076 KB |
Output is correct |
2 |
Correct |
8 ms |
16460 KB |
Output is correct |
3 |
Correct |
9 ms |
16972 KB |
Output is correct |
4 |
Correct |
9 ms |
17448 KB |
Output is correct |
5 |
Incorrect |
10 ms |
16268 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
850 ms |
71808 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
16204 KB |
Output is correct |
2 |
Incorrect |
124 ms |
33464 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
10 ms |
16268 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |