이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |