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 <iostream>
#define ll long long
using namespace std;
int n, ar[4][700], ar2[4][700], ar3[500001];
ll res = 0;
inline int getHash1(char a, char b)
{
return (a - 'A') * 26 + (b - 'A');
}
inline int getHash2(char a, char b, char c, char d)
{
return (a - 'A') * 17576 + (b - 'A') * 676 + (c - 'A') * 26 + (d - 'A');
}
int main()
{
cin >> n;
for (int i = 0; i < n; i++)
{
string a, b; cin >> a >> b;
res += ar[0][getHash1(b[0], b[1])];
res += ar[1][getHash1(a[1], b[1])];
res += ar[2][getHash1(a[0], a[1])];
res += ar[3][getHash1(a[0], b[0])];
ar[0][getHash1(a[0], a[1])]++;
ar[1][getHash1(a[0], b[0])]++;
ar[2][getHash1(b[0], b[1])]++;
ar[3][getHash1(a[1], b[1])]++;
if (a[1] == b[0])
{
res -= ar2[0][getHash1(a[0], b[0])];
res -= ar2[2][getHash1(a[1], b[1])];
ar2[0][getHash1(a[1], b[1])]++;
ar2[2][getHash1(a[0], b[0])]++;
}
if (a[0] == b[1])
{
res -= ar2[1][getHash1(a[1], b[1])];
res -= ar2[3][getHash1(a[0], b[0])];
ar2[1][getHash1(a[0], b[0])]++;
ar2[3][getHash1(a[1], b[1])]++;
}
res -= ar3[getHash2(a[1], a[0], b[1], b[0])];
res -= ar3[getHash2(b[0], b[1], a[0], a[1])];
if (a[0] == b[1] && a[1] == b[0])
{
res += 3 * ar3[getHash2(a[1], a[0], a[0], a[1])];
}
ar3[getHash2(a[0], a[1], b[0], b[1])]++;
}
cout << res << "\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... |