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>
#define int long long
#define endl '\n'
using namespace std;
int a[16][1000000];
int idk;
int git(char chr[2][2]){
int b=0,g=1;
for(int i=0;i<2;i++){
for(int w=0;w<2;w++){
b+=g*(chr[i][w]-'A');
g*=27;
}
}
return a[idk][b];
}
void incr(char chr[2][2]){
int b=0,g=1;
for(int i=0;i<2;i++){
for(int w=0;w<2;w++){
b+=g*(chr[i][w]-'A');
g*=27;
}
}
a[idk][b]++;
}
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n;
cin>>n;
int ans=0;
for(int i=0;i<n;i++){
char chr[2][2];
for(int w=0;w<2;w++){
for(int j=0;j<2;j++){
cin>>chr[w][j];
}
}
for(int w=1;w<(1<<4);w++){
char G[2][2];
G[0][0]='Z'+1,G[1][0]='Z'+1,G[0][1]='Z'+1,G[1][1]='Z'+1;
bool bl=1;
for(int j=0;j<4;j++){
if((1<<j)&w){
if(j==2){
if(G[1][0]!='Z'+1&&G[1][0]!=chr[0][0])bl=0;
if(G[1][1]!='Z'+1&&G[1][1]!=chr[0][1])bl=0;
G[1][0]=chr[0][0];
G[1][1]=chr[0][1];
}
if(j==3){
if(G[0][0]!='Z'+1&&G[0][0]!=chr[0][1])bl=0;
if(G[1][0]!='Z'+1&&G[1][0]!=chr[1][1])bl=0;
G[0][0]=chr[0][1];
G[1][0]=chr[1][1];
}
if(j==0){
if(G[0][0]!='Z'+1&&G[0][0]!=chr[1][0])bl=0;
if(G[0][1]!='Z'+1&&G[0][1]!=chr[1][1])bl=0;
G[0][0]=chr[1][0];
G[0][1]=chr[1][1];
}
if(j==1){
if(G[0][1]!='Z'+1&&G[0][1]!=chr[0][0])bl=0;
if(G[1][1]!='Z'+1&&G[1][1]!=chr[1][0])bl=0;
G[0][1]=chr[0][0];
G[1][1]=chr[1][0];
}
}
}
if(!bl)continue;
idk=w-1;
ans+=git(G)*(__builtin_popcount(w)%2?1:-1);
}
for(int w=1;w<(1<<4);w++){
char G[2][2];
G[0][0]='Z'+1,G[1][0]='Z'+1,G[0][1]='Z'+1,G[1][1]='Z'+1;
for(int j=0;j<4;j++){
if((1<<j)&w){
if(j==0){
G[0][0]=chr[0][0];
G[0][1]=chr[0][1];
}
if(j==1){
G[0][1]=chr[0][1];
G[1][1]=chr[1][1];
}
if(j==2){
G[1][0]=chr[1][0];
G[1][1]=chr[1][1];
}
if(j==3){
G[0][0]=chr[0][0];
G[1][0]=chr[1][0];
}
}
}
idk=w-1;
incr(G);
}
// cout<<ans<<endl;
}
cout<<ans;
}
# | 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... |