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;
const int MAXEMPAT=457000,MAXDUA=680;
int kiri[MAXDUA],kanan[MAXDUA],atas[MAXDUA],bawah[MAXDUA],cnt[MAXEMPAT];
int dua(int x,int y){
return 26*x+y;
}
int empat(int u,int v,int x,int y){
return 26*26*26*u+26*26*v+26*x+y;
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int n;
long long ans=0;
char a,b,c,d;
cin >> n;
for(int i=1;i<=n;i++){
cin >> a >> b >> c >> d;
cnt[empat(a-'A',b-'A',c-'A',d-'A')]++;
kiri[dua(a-'A',c-'A')]++;
kanan[dua(b-'A',d-'A')]++;
atas[dua(a-'A',b-'A')]++;
bawah[dua(c-'A',d-'A')]++;
}
for(int i=0;i<676;i++){
ans+=1LL*kiri[i]*kanan[i];
ans+=1LL*atas[i]*bawah[i];
}
for(int i=0;i<26;i++){
for(int j=0;j<26;j++){
for(int k=0;k<26;k++){
for(int l=0;l<26;l++){
int x=empat(i,j,k,l),y=empat(k,l,i,j);
if(x<y)ans-=1LL*cnt[x]*cnt[y];
y=empat(j,i,l,k);
if(x<y)ans-=1LL*cnt[x]*cnt[y];
}
}
}
}
for(int i=0;i<26;i++){
for(int j=0;j<26;j++){
for(int k=0;k<26;k++){
for(int l=0;l<26;l++){
int x=empat(k,i,i,j),y=empat(i,j,j,l);
if(x!=y)ans-=1LL*cnt[x]*cnt[y];
x=empat(i,j,k,i);y=empat(j,l,i,j);
if(x!=y)ans-=1LL*cnt[x]*cnt[y];
}
}
}
}
//inklusi eksklusi
for(int i=0;i<26;i++){
for(int j=i+1;j<26;j++){
int x=empat(i,j,j,i),y=empat(j,i,i,j);
ans+=3LL*cnt[x]*cnt[y];
}
ans-=2LL*cnt[empat(i,i,i,i)];
}
for(int i=0;i<26;i++){
for(int j=0;j<26;j++){
if(i==j)continue;
ans-=1LL*cnt[empat(i,j,i,j)];
ans-=1LL*cnt[empat(i,i,j,j)];
}
}
cout << ans << '\n';
return 0;
}
# | 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... |