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;
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
ll ile1[26][26][4], ile2[26][26][4], ile[26][26][26][26], ans;
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int n;
cin >> n;
while(n--) {
char c1, c2, c3, c4;
cin >> c1 >> c2 >> c3 >> c4;
int a=c1-'A', b=c2-'A', c=c4-'A', d=c3-'A';
ans+=ile1[a][b][2]+ile1[d][c][0]+ile1[a][d][1]+ile1[b][c][3];
ans-=ile[d][c][b][a]+ile[b][a][d][c];
if(a==c) ans-=ile2[a][b][0]+ile2[c][d][2];
if(b==d) ans-=ile2[b][c][1]+ile2[d][a][3];
if(a==c && b==d) ans+=3*ile[b][a][b][a];
++ile1[a][b][0]; ++ile1[d][c][2]; ++ile1[a][d][3]; ++ile1[b][c][1];
++ile[a][b][c][d];
if(a==c) {
++ile2[d][a][0];
++ile2[b][a][2];
}
if(b==d) {
++ile2[a][b][1];
++ile2[c][b][3];
}
}
cout << ans << '\n';
}
# | 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... |