This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#pragma optimize("Ofast")
//#pragma optimize("unroll-loops")
//#pragma traget("avx,avx2")
#include <iostream>
#include <cmath>
#include <algorithm>
#include <stdio.h>
#include <cstdint>
#include <cstring>
#include <string>
#include <cstdlib>
#include <vector>
#include <bitset>
#include <map>
#include <queue>
#include <ctime>
#include <stack>
#include <set>
#include <list>
#include <random>
#include <deque>
#include <functional>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <complex>
#include <numeric>
#include <cassert>
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <thread>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define el '\n'
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define point pair <ll, ll>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using namespace std;
#include <random>
mt19937 rnd(time(0));
const ll INF = 1e18 + 10;
const ll inf = 1e9 + 10;
const ll maxn = 5e5 + 10;
const ll mod = 1e9 + 7;
const ll K = 2e4 + 10;
const ll LOG = 20;
ll cnt[26][26][26][26][16];
void solve() {
ll n;
cin >> n;
vector <ll> count_bits(16);
for (ll i = 0; i < 16; i++)
for (ll j = 0; j < 4; j++)
count_bits[i] += (i >> j & 1);
ll ans = 0;
for (ll i = 0; i < n; i++) {
ll val[4];
char x;
cin >> x; val[0] = x - 'A';
cin >> x; val[1] = x - 'A';
cin >> x; val[2] = x - 'A';
cin >> x; val[3] = x - 'A';
ll cur = 0;
for (ll mask = 1; mask < (1 << 4); mask++) {
ll take[4] = {0, 0, 0, 0}, use[4] = {0, 0, 0, 0};
if (mask & (1 << 0)) {
take[0] = val[2];
take[1] = val[3];
use[0] |= 1 << val[2];
use[1] |= 1 << val[3];
}
if (mask & (1 << 1)) {
take[1] = val[0];
take[3] = val[2];
use[1] |= 1 << val[0];
use[3] |= 1 << val[2];
}
if (mask & (1 << 2)) {
take[2] = val[0];
take[3] = val[1];
use[2] |= 1 << val[0];
use[3] |= 1 << val[1];
}
if (mask & (1 << 3)) {
take[0] = val[1];
take[2] = val[3];
use[0] |= 1 << val[1];
use[2] |= 1 << val[3];
}
bool ok = 1;
for (ll j = 0; j < 4; j++)
if ((use[j] & (use[j] - 1)))
ok = 0;
if (!ok) continue;
if (count_bits[mask] % 2) cur += cnt[take[0]][take[1]][take[2]][take[3]][mask];
else cur -= cnt[take[0]][take[1]][take[2]][take[3]][mask];
}
ans += cur;
for (ll mask = 0; mask < (1 << 4); mask++) {
ll take[4] = {0, 0, 0, 0};
if (mask & (1 << 0)) {
take[0] = val[0];
take[1] = val[1];
}
if (mask & (1 << 1)) {
take[1] = val[1];
take[3] = val[3];
}
if (mask & (1 << 2)) {
take[2] = val[2];
take[3] = val[3];
}
if (mask & (1 << 3)) {
take[0] = val[0];
take[2] = val[2];
}
cnt[take[0]][take[1]][take[2]][take[3]][mask]++;
}
}
cout << ans << el;
return;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int tests = 1;
//cin >> tests;
while (tests--)
solve();
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... |