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, 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 x : arr[i][j]) {
if (!used[x]) {
cur = cur * 26 + f(str[i][x]);
used[x] = 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 x : arr[i][j]) {
if (!used[x]) {
cur = cur * 26 + f(str[i][x]);
used[x] = 1;
}
}
}
}
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... |