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 X first
#define Y second
#define ll long long
#define pii pair<int, int>
#define pb push_back
#define vec vector
#define siz size()
#define pri(i, poc, n, pov) for(int i = (int) poc; i < (int) n; i += (int) pov)
#define od(i, poc, n, pov) for(int i = (int) poc; i > (int) n; i -= (int) pov)
using namespace std;
const ll INF = 1e18;
const int LOG = 20;
const int OFF = (1 << LOG);
const int MOD = 1e9 + 7;
const int lx[8] = {1, -1, 0, 0, -1, 1, 1, -1};
const int ly[8] = {0, 0, 1, -1, -1, 1, -1, 1};
const int N = 1e5 + 10;
int abs(int x){
if(x < 0)
return -x;
return x;
}
ll a[26][26], b[26][26], c[26][26], d[26][26];
ll bc[26][26][26], cd[26][26][26], ad[26][26][26], ab[26][26][26];
ll all[26][26][26][26];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
setprecision(9);
int n;
cin >> n;
ll ans = 0;
pri(i, 0, n, 1){
char s1, s2, s3, s4;
cin >> s1 >> s2 >> s3 >> s4;
int x = s1 - 'A';
int y = s2 - 'A';
int z = s3 - 'A';
int w = s4 - 'A';
ans += c[x][y] + d[z][x] + a[z][w] + b[y][w];
if(y == z){
ans -= ab[w][z][w];
ans -= cd[x][y][x];
}
if(x == w){
ans -= bc[y][w][y];
ans -= ad[z][y][z];
}
if(x == w && y == z) ans += all[y][x][y][x];
if(x == z && w == y) ans -= all[w][z][x][y];
if(x == y && z == w) ans -= all[x][y][w][z];
a[y][x]++;
b[x][z]++;
c[z][w]++;
d[w][y]++;
ab[y][x][z]++;
ad[w][y][x]++;
bc[x][z][w]++;
cd[z][w][y]++;
all[y][x][z][w]++;
}
cout << ans;
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... |