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