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;
long long n, ans;
char grid[500005][2][2];
unordered_map<int, int> up, lt, rt, dn, lu, ur, rd, dl, all;
int con1(char a, char b){
return 26*(int)(a-'A')+(int)(b-'A');
}
int con2(char a, char b, char c){
return 26*26*(int)(a-'A')+26*(int)(b-'A')+(int)(c-'A');
}
int con3(char a, char b, char c, char d){
return 26*26*26*(int)(a-'A')+26*26*(int)(b-'A')+26*(int)(c-'A')+(int)(d-'A');
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for(int i=0; i<n; i++){
for(int j=0; j<2; j++){
for(int k=0; k<2; k++){
cin >> grid[i][j][k];
}
}
}
ans=0;
for(int i=0; i<n; i++){
char a=grid[i][0][0], b=grid[i][0][1], c=grid[i][1][0], d=grid[i][1][1];
ans+=up[con1(c, d)]+rt[con1(a, c)]+dn[con1(a, b)]+lt[con1(b, d)];
ans-=all[con3(c, d, a, b)]+all[con3(b, a, d, c)];
if(a==d) ans-=ur[con2(c, a, c)]+dl[con2(b, a, b)];
if(b==c) ans-=lu[con2(d, b, d)]+rd[con2(a, b, a)];
if(a==d && b==c) ans+=3*all[con3(b, a, a, b)];
up[con1(a, b)]++;
rt[con1(b, d)]++;
dn[con1(c, d)]++;
lt[con1(a, c)]++;
lu[con2(c, a, b)]++;
ur[con2(a, b, d)]++;
rd[con2(b, d, c)]++;
dl[con2(d, c, a)]++;
all[con3(a, b, c, d)]++;
}
cout << ans << endl;
}
# | 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... |