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;
int L[27][27];
int D[27][27];
int G[27][27];
int P[27][27];
int LD[27][27][27][27];
int LP[27][27][27][27];
int LG[27][27][27][27];
int PD[27][27][27][27];
int PG[27][27][27][27];
int DG[27][27][27][27];
int LPDG[27][27];
int f(int a,int b,int c,int d)
{
int w=0;
w=L[b][d]+P[a][c]+D[a][b]+G[c][d]-LD[b][d][a][b]-LP[b][d][a][c]-LG[b][d][c][d]-PD[a][c][a][b]-PG[a][c][c][d]-DG[a][b][c][d];
if(a==d&&b==c)w+=3*LPDG[c][d];
return w;
}
void dodaj(int a,int b,int c,int d)
{
L[a][c]++;
P[b][d]++;
D[c][d]++;
G[a][b]++;
LP[a][c][b][d]++;
LD[a][c][c][d]++;
LG[a][c][a][b]++;
PD[b][d][c][d]++;
PG[b][d][a][b]++;
DG[c][d][a][b]++;
if(a==d&&b==c)LPDG[a][b]++;
}
int main()
{
int n;
cin>>n;
long long w=0;
for(int i=0;i<n;i++)
{
char x1,y1,x2,y2;
cin>>x1>>y1>>x2>>y2;
int a=x1-'A',b=y1-'A',c=x2-'A',d=y2-'A';
w+=f(a,b,c,d);
dodaj(a,b,c,d);
}
cout<<w;
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... |