This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |