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>
using namespace std;
int N;
int L[680], R[680], U[680], D[680];
bitset<680> vis1, vis2;
long long cnt[500000];
char aa, bb, cc, dd;
long long ans;
/*
AB
CD
*/
inline int num(char A, char B, char C, char D) {return 17576 * (A - 'A') + 676 * (B - 'A') + 26 * (C - 'A') + D - 'A';}
inline int num(char C, char D) {return 26 * (C - 'A') + D - 'A';}
inline int num(int A, int B, int C, int D) {return 17576 * (A) + 676 * (B) + 26 * (C) + D;}
inline int num(int C, int D) {return 26 * (C) + D;}
inline void match(int a, int b) {if(a > b) ans -= cnt[a] * cnt[b];}
inline void match2(int a, int b) {if(a != b) ans -= cnt[a] * cnt[b];}
int main() {
ios_base::sync_with_stdio(0);
cin >> N;
for(int i = 1; i <= N; i++) {
cin >> aa >> bb >> cc >> dd;
if(aa == bb && cc == dd) ans--;
if(aa == cc && bb == dd) ans--;
cnt[num(aa, bb, cc, dd)]++;
L[num(aa, cc)]++;
U[num(aa, bb)]++;
R[num(bb, dd)]++;
D[num(cc, dd)]++;
}
// cout << ans << "\n";
for(int i = 0; i < 26; i++) {
for(int j = 0; j < 26; j++) {
ans += L[num(i, j)] * R[num(i, j)];
ans += U[num(i, j)] * D[num(i, j)];
for(int k = 0; k < 26; k++) {
for(int l = 0; l < 26; l++) {
match(num(i, j, k, l), num(k, l, i, j));
match(num(i, j, k, l), num(j, i, l, k));
match2(num(i, j, k, i), num(j, l, i, j));
match2(num(k, i, i, j), num(i, j, j, l));
}
}
if(i < j) ans += 3 * cnt[num(i, j, j, i)] * cnt[num(j, i, i, j)];
}
}
cout << ans << "\n";
cin >> N;
}
# | 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... |