#include <bits/stdc++.h>
using namespace std;
int N;
int L[680], R[680], U[680], D[680];
bitset<680> vis1, vis2;
long long cnt[500000];
char aa, bb, cc, dd;
long long ans;
/*
AB
CD
*/
inline int num(char A, char B, char C, char D) {return 17576 * (A - 'A') + 676 * (B - 'A') + 26 * (C - 'A') + D - 'A';}
inline int num(char C, char D) {return 26 * (C - 'A') + D - 'A';}
inline int num(int A, int B, int C, int D) {return 17576 * (A) + 676 * (B) + 26 * (C) + D;}
inline int num(int C, int D) {return 26 * (C) + D;}
inline void match(int a, int b) {if(a > b) ans -= cnt[a] * cnt[b];}
inline void match2(int a, int b) {if(a != b) ans -= cnt[a] * cnt[b];}
int main() {
ios_base::sync_with_stdio(0);
cin >> N;
for(int i = 1; i <= N; i++) {
cin >> aa >> bb >> cc >> dd;
if(aa == bb && cc == dd) ans--;
if(aa == cc && bb == dd) ans--;
cnt[num(aa, bb, cc, dd)]++;
L[num(aa, cc)]++;
U[num(aa, bb)]++;
R[num(bb, dd)]++;
D[num(cc, dd)]++;
}
// cout << ans << "\n";
for(int i = 0; i < 26; i++) {
for(int j = 0; j < 26; j++) {
ans += L[num(i, j)] * R[num(i, j)];
ans += U[num(i, j)] * D[num(i, j)];
for(int k = 0; k < 26; k++) {
for(int l = 0; l < 26; l++) {
match(num(i, j, k, l), num(k, l, i, j));
match(num(i, j, k, l), num(j, i, l, k));
match2(num(i, j, k, i), num(j, l, i, j));
match2(num(k, i, i, j), num(i, j, j, l));
}
}
if(i < j) ans += 3 * cnt[num(i, j, j, i)] * cnt[num(j, i, i, j)];
}
}
cout << ans << "\n";
cin >> N;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
4 |
Correct |
3 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
2048 KB |
Output is correct |
3 |
Correct |
5 ms |
768 KB |
Output is correct |
4 |
Correct |
4 ms |
3712 KB |
Output is correct |
5 |
Correct |
6 ms |
2048 KB |
Output is correct |
6 |
Correct |
4 ms |
2816 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
8 |
Correct |
3 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
512 KB |
Output is correct |
11 |
Correct |
3 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 ms |
4096 KB |
Output is correct |
2 |
Correct |
76 ms |
3968 KB |
Output is correct |
3 |
Correct |
57 ms |
4084 KB |
Output is correct |
4 |
Correct |
55 ms |
4096 KB |
Output is correct |
5 |
Correct |
48 ms |
3968 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
11 ms |
4096 KB |
Output is correct |
3 |
Correct |
34 ms |
3968 KB |
Output is correct |
4 |
Correct |
19 ms |
3968 KB |
Output is correct |
5 |
Correct |
31 ms |
3968 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
2048 KB |
Output is correct |
3 |
Correct |
5 ms |
768 KB |
Output is correct |
4 |
Correct |
4 ms |
3712 KB |
Output is correct |
5 |
Correct |
6 ms |
2048 KB |
Output is correct |
6 |
Correct |
4 ms |
2816 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
8 |
Correct |
3 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
512 KB |
Output is correct |
11 |
Correct |
3 ms |
512 KB |
Output is correct |
12 |
Correct |
63 ms |
4096 KB |
Output is correct |
13 |
Correct |
76 ms |
3968 KB |
Output is correct |
14 |
Correct |
57 ms |
4084 KB |
Output is correct |
15 |
Correct |
55 ms |
4096 KB |
Output is correct |
16 |
Correct |
48 ms |
3968 KB |
Output is correct |
17 |
Correct |
11 ms |
4096 KB |
Output is correct |
18 |
Correct |
34 ms |
3968 KB |
Output is correct |
19 |
Correct |
19 ms |
3968 KB |
Output is correct |
20 |
Correct |
31 ms |
3968 KB |
Output is correct |
21 |
Correct |
14 ms |
3968 KB |
Output is correct |
22 |
Correct |
54 ms |
3968 KB |
Output is correct |
23 |
Correct |
36 ms |
4096 KB |
Output is correct |
24 |
Correct |
34 ms |
3968 KB |
Output is correct |