#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, 4> arr[MAXN];
map<ll, int> cnt[16];
int n;
int encode(char a, char b) {
return (a - 'A') * 26 + (b - '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;
arr[i][0] = encode(x[0], x[1]);
arr[i][1] = encode(x[0], y[0]);
arr[i][2] = encode(x[1], y[1]);
arr[i][3] = encode(y[0], y[1]);
}
ll ans = 0;
for (int i = 0; i < n; i++) {
for (int mask = 1; mask < 16; mask++) {
ll cur = 0;
for (int j = 0; j < 4; j++) {
if (bit(mask, j)) {
cur = cur * 26 * 26 + arr[i][j];
}
}
int pp = __builtin_popcount(mask);
auto it = cnt[mask].find(cur);
ll tmp = (it == cnt[mask].end() ? 0 : it -> second);
if (pp % 2 == 1) {
ans += tmp;
}
else {
ans -= tmp;
}
}
reverse(all(arr[i]));
for (int mask = 1; mask < 16; mask++) {
ll cur = 0;
for (int j = 0; j < 4; j++) {
if (bit(mask, j)) {
cur = cur * 26 * 26 + arr[i][j];
}
}
cnt[mask][cur]++;
}
}
cout << ans << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
3 ms |
844 KB |
Output is correct |
7 |
Correct |
7 ms |
1040 KB |
Output is correct |
8 |
Correct |
15 ms |
2192 KB |
Output is correct |
9 |
Correct |
13 ms |
1740 KB |
Output is correct |
10 |
Correct |
13 ms |
1868 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1087 ms |
46788 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
669 ms |
26956 KB |
Output is correct |
3 |
Execution timed out |
1092 ms |
43552 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
3 ms |
844 KB |
Output is correct |
3 |
Correct |
7 ms |
1040 KB |
Output is correct |
4 |
Correct |
15 ms |
2192 KB |
Output is correct |
5 |
Correct |
13 ms |
1740 KB |
Output is correct |
6 |
Correct |
13 ms |
1868 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Execution timed out |
1087 ms |
46788 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |