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;
const int N = 456976+5, MAX1 = 26*26+5, MAX2 = 26*26*26+5, MAX3 = 26*26*26*26+5;
int n, ans;
int val[N][4];
int cnt[4][MAX3][4];
inline int parse(char a, char b) {
return (int)(a - 'A') * 26 + (int)(b - 'A');
}
inline int parse(char a, char b, char c) {
return (int)(a - 'A') * 26 * 26 + (int)(b - 'A') * 26
+ (int)(c - 'A');
}
inline int parse(char a, char b, char c, char d) {
return (int)(a - 'A') * 26 * 26 * 26 + (int)(b - 'A') * 26 * 26
+ (int)(c - 'A') * 26 + (int)(d - 'A');
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
ans = 0;
cin >> n;
for(int i = 0; i < n; i++) {
char c[4];
for(int j = 0; j < 4; j++)
cin >> c[j];
swap(c[2], c[3]);
val[i][0] = parse(c[0], c[1]);
val[i][1] = parse(c[1], c[2]);
val[i][2] = parse(c[3], c[2]);
val[i][3] = parse(c[0], c[3]);
//ans
//type 0
for(int j = 0; j < 4; j++)
ans += cnt[0][val[i][j]][j^2];
//type 1
for(int j = 0; j < 4; j++) {
char lst = 'a';
bool ok = 1;
for(int k = 0; k < 4 && ok; k++) {
if(k == j || k == (j^2)) continue;
if(lst == 'a') lst = c[k];
else if(lst != c[k]) ok = 0;
}
if(ok) {
ans -= cnt[1][parse(c[j^2], lst, c[j^2])][j^2];
}
}
//type 2
ans -= cnt[2][parse(c[3], c[2], c[0], c[1])][0];
ans -= cnt[2][parse(c[0], c[3], c[1], c[2])][1];
//type 3
if(c[0] == c[2] && c[1] == c[3]) {
ans += 3 * cnt[3][parse(c[1], c[0], c[3], c[2])][0];
}
//cnt
//type 0
for(int j = 0; j < 4; j++)
cnt[0][val[i][j]][j]++;
//type 1
for(int j = 0; j < 4; j++) {
char lst = 'a';
bool ok = 1;
for(int k = 0; k < 4 && ok; k++) {
if(k == j || k == (j^2)) continue;
if(lst == 'a') lst = c[k];
else if(lst != c[k]) ok = 0;
}
if(ok) {
cnt[1][parse(lst, c[j^2], lst)][j]++;
}
}
//type 2
cnt[2][parse(c[0], c[1], c[3], c[2])][0]++;
cnt[2][parse(c[1], c[2], c[0], c[3])][1]++;
//type 3
if(c[0] == c[2] && c[1] == c[3]) {
cnt[3][parse(c[0], c[1], c[2], c[3])][0]++;
}
}
cout << ans << '\n';
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... |