#include <bits/stdc++.h>
using namespace std;
const int A = 27;
int wyst[A][A][A][A];
int main () {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
long long wyn = 0;
for (int i = 1; i <= n; i++) {
string s;
int a, b, c, d;
cin >> s;
a = s[0]-'A'; b = s[1]-'A';
cin >> s;
d = s[0]-'A'; c = s[1]-'A';
int x = 26;
wyn += wyst[d][c][26][26]; //stykaja sie z dolem
wyn += wyst[b][26][26][c]; //stykaja sie z prawa
wyn += wyst[26][26][b][a]; //stykaja sie z gora
wyn += wyst[26][a][d][26]; //stykaja sie z lewa
if (a == c) {
wyn -= wyst[b][x][b][a];
wyn -= wyst[d][c][d][x];
}
if (b == d) {
wyn -= wyst[b][c][x][c];
wyn -= wyst[x][a][d][a];
}
wyn -= wyst[d][c][b][a];
wyn -= wyst[b][a][d][c];
if (a == c && b == d) {
wyn += 3*wyst[b][c][b][c];
}
wyst[a][b][26][26]++;
wyst[26][b][c][26]++;
wyst[26][26][c][d]++;
wyst[a][26][26][d]++;
wyst[a][x][c][d]++;
wyst[a][b][c][x]++;
wyst[a][b][x][d]++;
wyst[x][b][c][d]++;
wyst[a][b][c][d]++;
}
cout << wyn << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
712 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
2028 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
3 ms |
2388 KB |
Output is correct |
9 |
Correct |
2 ms |
1752 KB |
Output is correct |
10 |
Correct |
3 ms |
2260 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
81 ms |
5056 KB |
Output is correct |
2 |
Correct |
82 ms |
5052 KB |
Output is correct |
3 |
Correct |
121 ms |
4928 KB |
Output is correct |
4 |
Correct |
79 ms |
4924 KB |
Output is correct |
5 |
Correct |
97 ms |
4944 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
9 ms |
2644 KB |
Output is correct |
3 |
Correct |
60 ms |
4040 KB |
Output is correct |
4 |
Correct |
43 ms |
3412 KB |
Output is correct |
5 |
Correct |
24 ms |
3412 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
2028 KB |
Output is correct |
3 |
Correct |
1 ms |
724 KB |
Output is correct |
4 |
Correct |
3 ms |
2388 KB |
Output is correct |
5 |
Correct |
2 ms |
1752 KB |
Output is correct |
6 |
Correct |
3 ms |
2260 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
596 KB |
Output is correct |
11 |
Correct |
1 ms |
712 KB |
Output is correct |
12 |
Correct |
81 ms |
5056 KB |
Output is correct |
13 |
Correct |
82 ms |
5052 KB |
Output is correct |
14 |
Correct |
121 ms |
4928 KB |
Output is correct |
15 |
Correct |
79 ms |
4924 KB |
Output is correct |
16 |
Correct |
97 ms |
4944 KB |
Output is correct |
17 |
Correct |
9 ms |
2644 KB |
Output is correct |
18 |
Correct |
60 ms |
4040 KB |
Output is correct |
19 |
Correct |
43 ms |
3412 KB |
Output is correct |
20 |
Correct |
24 ms |
3412 KB |
Output is correct |
21 |
Correct |
16 ms |
2888 KB |
Output is correct |
22 |
Correct |
48 ms |
4420 KB |
Output is correct |
23 |
Correct |
36 ms |
3676 KB |
Output is correct |
24 |
Correct |
39 ms |
3728 KB |
Output is correct |