#include <bits/stdc++.h>
using namespace std;
int kon(char z) {
return (int)z - 65;
}
int l[30][30];
int p[30][30];
int g[30][30];
int d[30][30];
int c[30][30][30][30];
int gp[30][30][30];
int dl[30][30][30];
int lg[30][30][30];
int pd[30][30][30];
int main() {
int n;
cin >> n;
int ans = 0;
for(int i = 1; i <= n; i++) {
char tmp1, tmp2, tmp3, tmp4;
cin >> tmp1 >> tmp2 >> tmp3 >> tmp4;
int z1 = kon(tmp1);
int z2 = kon(tmp2);
int z3 = kon(tmp3);
int z4 = kon(tmp4);
ans += d[z1][z2];
ans += l[z2][z4];
ans += g[z3][z4];
ans += p[z1][z3];
if(z1 == z4) {
ans -= dl[z2][z1][z2];
ans -= gp[z3][z1][z3];
}
if(z2 == z3) {
ans -= lg[z4][z2][z4];
ans -= pd[z1][z2][z1];
}
if(z1 == z4 && z2 == z3) {
ans += 3 * c[z2][z1][z1][z2];
}
ans -= c[z2][z1][z4][z3];
ans -= c[z3][z4][z1][z2];
g[z1][z2]++;
p[z2][z4]++;
d[z3][z4]++;
l[z1][z3]++;
lg[z3][z1][z2]++;
gp[z1][z2][z4]++;
pd[z2][z4][z3]++;
dl[z4][z3][z1]++;
c[z1][z2][z3][z4]++;
}
printf("%d\n", ans);
}
# |
Verdict |
Execution time |
Memory |
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 |
872 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
872 KB |
Output is correct |
5 |
Correct |
1 ms |
312 KB |
Output is correct |
6 |
Correct |
2 ms |
2132 KB |
Output is correct |
7 |
Correct |
1 ms |
852 KB |
Output is correct |
8 |
Correct |
3 ms |
3028 KB |
Output is correct |
9 |
Correct |
3 ms |
2004 KB |
Output is correct |
10 |
Correct |
3 ms |
2632 KB |
Output is correct |
11 |
Correct |
1 ms |
308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
161 ms |
5824 KB |
Output is correct |
2 |
Correct |
165 ms |
5824 KB |
Output is correct |
3 |
Correct |
171 ms |
5824 KB |
Output is correct |
4 |
Correct |
155 ms |
5704 KB |
Output is correct |
5 |
Correct |
137 ms |
5824 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
308 KB |
Output is correct |
2 |
Correct |
17 ms |
3388 KB |
Output is correct |
3 |
Correct |
88 ms |
4780 KB |
Output is correct |
4 |
Correct |
63 ms |
4164 KB |
Output is correct |
5 |
Correct |
67 ms |
4156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
312 KB |
Output is correct |
2 |
Correct |
2 ms |
2132 KB |
Output is correct |
3 |
Correct |
1 ms |
852 KB |
Output is correct |
4 |
Correct |
3 ms |
3028 KB |
Output is correct |
5 |
Correct |
3 ms |
2004 KB |
Output is correct |
6 |
Correct |
3 ms |
2632 KB |
Output is correct |
7 |
Correct |
1 ms |
308 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 |
872 KB |
Output is correct |
12 |
Correct |
161 ms |
5824 KB |
Output is correct |
13 |
Correct |
165 ms |
5824 KB |
Output is correct |
14 |
Correct |
171 ms |
5824 KB |
Output is correct |
15 |
Correct |
155 ms |
5704 KB |
Output is correct |
16 |
Correct |
137 ms |
5824 KB |
Output is correct |
17 |
Correct |
17 ms |
3388 KB |
Output is correct |
18 |
Correct |
88 ms |
4780 KB |
Output is correct |
19 |
Correct |
63 ms |
4164 KB |
Output is correct |
20 |
Correct |
67 ms |
4156 KB |
Output is correct |
21 |
Correct |
39 ms |
3864 KB |
Output is correct |
22 |
Correct |
113 ms |
5180 KB |
Output is correct |
23 |
Correct |
67 ms |
4428 KB |
Output is correct |
24 |
Correct |
88 ms |
4416 KB |
Output is correct |