#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
512 KB |
Output is correct |
3 |
Correct |
0 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
392 KB |
Output is correct |
2 |
Correct |
3 ms |
3968 KB |
Output is correct |
3 |
Correct |
1 ms |
1536 KB |
Output is correct |
4 |
Correct |
5 ms |
7424 KB |
Output is correct |
5 |
Correct |
3 ms |
3840 KB |
Output is correct |
6 |
Correct |
4 ms |
5632 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
512 KB |
Output is correct |
10 |
Correct |
0 ms |
512 KB |
Output is correct |
11 |
Correct |
1 ms |
640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
143 ms |
20312 KB |
Output is correct |
2 |
Correct |
140 ms |
20088 KB |
Output is correct |
3 |
Correct |
135 ms |
20216 KB |
Output is correct |
4 |
Correct |
138 ms |
20216 KB |
Output is correct |
5 |
Correct |
147 ms |
20088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
22 ms |
8448 KB |
Output is correct |
3 |
Correct |
115 ms |
13740 KB |
Output is correct |
4 |
Correct |
65 ms |
11128 KB |
Output is correct |
5 |
Correct |
65 ms |
11128 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
392 KB |
Output is correct |
2 |
Correct |
3 ms |
3968 KB |
Output is correct |
3 |
Correct |
1 ms |
1536 KB |
Output is correct |
4 |
Correct |
5 ms |
7424 KB |
Output is correct |
5 |
Correct |
3 ms |
3840 KB |
Output is correct |
6 |
Correct |
4 ms |
5632 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
512 KB |
Output is correct |
10 |
Correct |
0 ms |
512 KB |
Output is correct |
11 |
Correct |
1 ms |
640 KB |
Output is correct |
12 |
Correct |
143 ms |
20312 KB |
Output is correct |
13 |
Correct |
140 ms |
20088 KB |
Output is correct |
14 |
Correct |
135 ms |
20216 KB |
Output is correct |
15 |
Correct |
138 ms |
20216 KB |
Output is correct |
16 |
Correct |
147 ms |
20088 KB |
Output is correct |
17 |
Correct |
22 ms |
8448 KB |
Output is correct |
18 |
Correct |
115 ms |
13740 KB |
Output is correct |
19 |
Correct |
65 ms |
11128 KB |
Output is correct |
20 |
Correct |
65 ms |
11128 KB |
Output is correct |
21 |
Correct |
40 ms |
10488 KB |
Output is correct |
22 |
Correct |
106 ms |
17376 KB |
Output is correct |
23 |
Correct |
74 ms |
14072 KB |
Output is correct |
24 |
Correct |
71 ms |
14200 KB |
Output is correct |