//#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 |
1 |
Correct |
1 ms |
2512 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
3 ms |
25176 KB |
Output is correct |
4 |
Correct |
2 ms |
14936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2512 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
3 ms |
25176 KB |
Output is correct |
4 |
Correct |
2 ms |
14936 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
5 ms |
26716 KB |
Output is correct |
7 |
Correct |
3 ms |
12636 KB |
Output is correct |
8 |
Correct |
7 ms |
33372 KB |
Output is correct |
9 |
Correct |
7 ms |
23132 KB |
Output is correct |
10 |
Correct |
6 ms |
24408 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
237 ms |
60224 KB |
Output is correct |
2 |
Correct |
226 ms |
60240 KB |
Output is correct |
3 |
Correct |
221 ms |
60240 KB |
Output is correct |
4 |
Correct |
231 ms |
60308 KB |
Output is correct |
5 |
Correct |
225 ms |
60344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
50 ms |
55824 KB |
Output is correct |
3 |
Correct |
157 ms |
57684 KB |
Output is correct |
4 |
Correct |
90 ms |
57424 KB |
Output is correct |
5 |
Correct |
90 ms |
56964 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
5 ms |
26716 KB |
Output is correct |
3 |
Correct |
3 ms |
12636 KB |
Output is correct |
4 |
Correct |
7 ms |
33372 KB |
Output is correct |
5 |
Correct |
7 ms |
23132 KB |
Output is correct |
6 |
Correct |
6 ms |
24408 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
2512 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
3 ms |
25176 KB |
Output is correct |
11 |
Correct |
2 ms |
14936 KB |
Output is correct |
12 |
Correct |
237 ms |
60224 KB |
Output is correct |
13 |
Correct |
226 ms |
60240 KB |
Output is correct |
14 |
Correct |
221 ms |
60240 KB |
Output is correct |
15 |
Correct |
231 ms |
60308 KB |
Output is correct |
16 |
Correct |
225 ms |
60344 KB |
Output is correct |
17 |
Correct |
50 ms |
55824 KB |
Output is correct |
18 |
Correct |
157 ms |
57684 KB |
Output is correct |
19 |
Correct |
90 ms |
57424 KB |
Output is correct |
20 |
Correct |
90 ms |
56964 KB |
Output is correct |
21 |
Correct |
67 ms |
58032 KB |
Output is correct |
22 |
Correct |
177 ms |
59604 KB |
Output is correct |
23 |
Correct |
110 ms |
58960 KB |
Output is correct |
24 |
Correct |
133 ms |
58960 KB |
Output is correct |