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 pb push_back
using namespace std;
int n,satu,dua,empat;
vector<vector<int> > pairu(676*676+5),paird(676*676+5),pairr(676*676+5),pairl(676*676+5);
bool tmp1[680],tmp2[680],tmp3[680],tmp4[680];
bool ada[676*676+5];
string s[676*676+5],abaw,tms1,tms2,kaki,tms;
int hsh(string a){
return int(a[0]-'A')*676*26+int(a[1]-'A')*676+int(a[2]-'A')*26+int(a[3]-'A');
}
string ts( char a, char b, char c , char d){
string ret = "";
ret.pb(a);
ret.pb(b);
ret.pb(c);
ret.pb(d);
return ret;
}
int main(){
cin>>n;
for(int i =1;i<=n;i++){
string a,b;
cin>>a>>b;
s[i] = a+b;
int u = (s[i][0]-'A')*26+ (s[i][1]-'A');
int d = (s[i][2]-'A')*26+ (s[i][3]-'A');
int l = (s[i][0]-'A')*26+ (s[i][2]-'A');
int r = (s[i][1]-'A')*26+ (s[i][3]-'A');
pairu[u].pb(d);
paird[d].pb(u);
pairl[l].pb(r);
pairr[r].pb(l);
ada[hsh(s[i])]=1;
}
for(int i =0;i<26*26;i++){
satu+= pairu[i].size()*paird[i].size();
memset(tmp1,0,sizeof(tmp1));
memset(tmp2,0,sizeof(tmp2));
memset(tmp3,0,sizeof(tmp3));
memset(tmp4,0,sizeof(tmp4));
for(auto j :pairu[i])tmp1[j]=1;
for(auto j :paird[i])tmp2[j]=1;
if(tmp1[i]&&tmp2[i])satu--;
satu+= pairl[i].size()*pairr[i].size();
for(auto j :pairl[i])tmp3[j]=1;
for(auto j :pairr[i])tmp4[j]=1;
if(tmp3[i]&&tmp4[i])satu--;
}
// cout<<satu<<endl;
for(int i =1;i<=n;i++){
abaw= ts(s[i][2],s[i][3],s[i][0],s[i][1]);
// cout<<abaw<<endl;
kaki=ts(s[i][1],s[i][0],s[i][3],s[i][2]);
if(s[i]!=abaw&&ada[hsh(abaw)])dua++;
if(s[i]!=kaki&&ada[hsh(kaki)])dua++;
if(s[i][0]==s[i][3]&&s[i][2]==s[i][1]){
tms = ts(s[i][1],s[i][0],s[i][3],s[i][2]);
if(s[i]!=tms&&ada[hsh(tms)])empat++;
}
if(s[i][1]==s[i][2]){
for(char j = 'A' ;j<='Z';j++){
tms1=ts(j,s[i][0],s[i][0],s[i][1]);
tms2 = ts(s[i][1],s[i][3],s[i][3],j);
if(s[i]!=tms1&&ada[hsh(tms1)])dua++;
if(s[i]!=tms2&&ada[hsh(tms2)])dua++;
}
}
if(s[i][0]==s[i][3]){
for(char j = 'A' ;j<='Z';j++){
tms1 = ts(s[i][1],j,s[i][0],s[i][1]);
tms2 = ts(s[i][2],s[i][0],j,s[i][2]);
if(s[i]!=tms1&&ada[hsh(tms1)])dua++;
if(s[i]!=tms2&&ada[hsh(tms2)])dua++;
}
}
}
// cout<<dua<<' '<<empat<<endl;
cout<<satu- dua/2 + (empat/2)*3<<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... |