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 <string>
#include <vector>
#include <iostream>
#include <unordered_set>
using namespace std;
inline int hashing(string s) {
return int(s[0] - 'A') * 26 * 26 * 26 + int(s[1] - 'A') * 26 * 26 + int(s[2] - 'A') * 26 + int(s[3] - 'A');
}
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
int N;
cin >> N;
vector<vector<int> > gl(676), gr(676), gu(676), gd(676);
vector<string> s(N);
vector<bool> st(676 * 676);
for (int i = 0; i < N; ++i) {
string sa, sb;
cin >> sa >> sb;
s[i] = sa + sb;
int cu = int(s[i][0] - 'A') * 26 + int(s[i][1] - 'A');
int cd = int(s[i][2] - 'A') * 26 + int(s[i][3] - 'A');
int cl = int(s[i][0] - 'A') * 26 + int(s[i][2] - 'A');
int cr = int(s[i][1] - 'A') * 26 + int(s[i][3] - 'A');
gu[cu].push_back(cd);
gd[cd].push_back(cu);
gl[cl].push_back(cr);
gr[cr].push_back(cl);
st[hashing(s[i])] = true;
}
int ans = 0;
for (int i = 0; i < 676; ++i) {
vector<int> va = gl[i], vb = gr[i];
ans += va.size() * vb.size();
vector<bool> fa(676), fb(676);
for (int j : va) fa[j] = true;
for (int j : vb) fb[j] = true;
if (fa[i] && fb[i]) --ans;
}
for (int i = 0; i < 676; ++i) {
vector<int> va = gu[i], vb = gd[i];
ans += va.size() * vb.size();
vector<bool> fa(676), fb(676);
for (int j : va) fa[j] = true;
for (int j : vb) fb[j] = true;
if (fa[i] && fb[i]) --ans;
}
int twos = 0, fours = 0;
for (int i = 0; i < N; ++i) {
string opp1 = string(1, s[i][2]) + string(1, s[i][3]) + string(1, s[i][0]) + string(1, s[i][1]);
string opp2 = string(1, s[i][1]) + string(1, s[i][0]) + string(1, s[i][3]) + string(1, s[i][2]);
if (s[i] != opp1 && st[hashing(opp1)]) ++twos;
if (s[i] != opp2 && st[hashing(opp2)]) ++twos;
if (s[i][1] == s[i][2]) {
for (char c = 'A'; c <= 'Z'; ++c) {
string opp3 = string(1, c) + string(1, s[i][0]) + string(1, s[i][0]) + string(1, s[i][1]);
string opp4 = string(1, s[i][2]) + string(1, s[i][3]) + string(1, s[i][3]) + string(1, c);
if (s[i] != opp3 && st[hashing(opp3)]) ++twos;
if (s[i] != opp4 && st[hashing(opp4)]) ++twos;
}
}
if (s[i][0] == s[i][3]) {
for (char c = 'A'; c <= 'Z'; ++c) {
string opp3 = string(1, s[i][1]) + string(1, c) + string(1, s[i][0]) + string(1, s[i][1]);
string opp4 = string(1, s[i][2]) + string(1, s[i][3]) + string(1, c) + string(1, s[i][2]);
if (s[i] != opp3 && st[hashing(opp3)]) ++twos;
if (s[i] != opp4 && st[hashing(opp4)]) ++twos;
}
}
if (s[i][0] == s[i][3] && s[i][1] == s[i][2]) {
string opp5 = string(1, s[i][1]) + string(1, s[i][0]) + string(1, s[i][0]) + string(1, s[i][1]);
if (s[i] != opp5 && st[hashing(opp5)]) ++fours;
}
}
twos /= 2;
fours /= 2;
cout << ans - twos + fours * 3 << endl;
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... |