#include<bits/stdc++.h>
using namespace std;
inline int hashing(string s) {
return int(s[0] - 'A') * 26 * 26 * 26 + int(s[1] - 'A') * 26 * 26 + int(s[2] - 'A') * 26 + int(s[3] - 'A');
}
int main() {
int n;
cin >> n;
vector<vector<int> > left(676), right(676), up(676), down(676);
vector<string> s(n);
vector<bool> st(676 * 676);
for (int i = 0; i < n; ++i) {
string sa, sb;
cin >> sa >> sb;
s[i] = sa + sb;
int cu = (s[i][0] - 'A') * 26 + (s[i][1] - 'A');
int cd = (s[i][2] - 'A') * 26 + (s[i][3] - 'A');
int cl = (s[i][0] - 'A') * 26 + (s[i][2] - 'A');
int cr = (s[i][1] - 'A') * 26 + (s[i][3] - 'A');
up[cu].push_back(cd);
down[cd].push_back(cu);
left[cl].push_back(cr);
right[cr].push_back(cl);
st[hashing(s[i])] = true;
}
int ans = 0;
for (int i = 0; i < 676; ++i) {
vector<int> a = left[i];
vector<int> b = right[i];
ans += a.size() * b.size();
vector<bool> arr1(676);
vector<bool> arr2(676);
for(int j = 0; j < a.size(); j++){
arr1[a[j]] = true;
}
for(int j = 0; j < b.size(); j++){
arr2[b[j]] = true;
}
if(arr2[i] && arr1[i]){
--ans;
}
}
for (int i = 0; i < 676; ++i) {
vector<int> a = up[i];
vector<int> b = down[i];
ans += a.size() * b.size();
vector<bool> arr1(676);
vector<bool> arr2(676);
for(int j = 0; j < a.size(); j++){
arr1[a[j]] = true;
}
for(int j = 0; j < b.size(); j++){
arr2[b[j]] = true;
}
if(arr2[i] && arr1[i]){
--ans;
}
}
int twos = 0, fours = 0;
for (int i = 0; i < n; ++i) {
string val1 = string(1, s[i][2]) + string(1, s[i][3]) + string(1, s[i][0]) + string(1, s[i][1]);
string val2 = string(1, s[i][1]) + string(1, s[i][0]) + string(1, s[i][3]) + string(1, s[i][2]);
if (s[i] != val1 && st[hashing(val1)]){
++twos;
}
if (s[i] != val2 && st[hashing(val2)]){
++twos;
}
if (s[i][1] == s[i][2]) {
for (char c = 'A'; c <= 'Z'; ++c) {
string opp3 = string(1, c) + string(1, s[i][0]) + string(1, s[i][0]) + string(1, s[i][1]);
string opp4 = string(1, s[i][2]) + string(1, s[i][3]) + string(1, s[i][3]) + string(1, c);
if (s[i] != opp3 && st[hashing(opp3)]) ++twos;
if (s[i] != opp4 && st[hashing(opp4)]) ++twos;
}
}
if (s[i][0] == s[i][3]) {
for (char c = 'A'; c <= 'Z'; ++c) {
string opp3 = string(1, s[i][1]) + string(1, c) + string(1, s[i][0]) + string(1, s[i][1]);
string opp4 = string(1, s[i][2]) + string(1, s[i][3]) + string(1, c) + string(1, s[i][2]);
if (s[i] != opp3 && st[hashing(opp3)]) ++twos;
if (s[i] != opp4 && st[hashing(opp4)]) ++twos;
}
}
if (s[i][0] == s[i][3] && s[i][1] == s[i][2]) {
string opp5 = string(1, s[i][1]) + string(1, s[i][0]) + string(1, s[i][0]) + string(1, s[i][1]);
if (s[i] != opp5 && st[hashing(opp5)]) ++fours;
}
}
twos /= 2;
fours /= 2;
cout << ans - twos + fours * 3 << endl;
return 0;
}
Compilation message
korteles.cpp: In function 'int main()':
korteles.cpp:33:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | for(int j = 0; j < a.size(); j++){
| ~~^~~~~~~~~~
korteles.cpp:36:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | for(int j = 0; j < b.size(); j++){
| ~~^~~~~~~~~~
korteles.cpp:49:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | for(int j = 0; j < a.size(); j++){
| ~~^~~~~~~~~~
korteles.cpp:52:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | for(int j = 0; j < b.size(); j++){
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
5 ms |
468 KB |
Output is correct |
8 |
Correct |
3 ms |
564 KB |
Output is correct |
9 |
Correct |
5 ms |
596 KB |
Output is correct |
10 |
Correct |
5 ms |
596 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
413 ms |
29440 KB |
Output is correct |
2 |
Correct |
407 ms |
29340 KB |
Output is correct |
3 |
Correct |
387 ms |
29456 KB |
Output is correct |
4 |
Correct |
392 ms |
29220 KB |
Output is correct |
5 |
Correct |
407 ms |
29312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
32 ms |
3664 KB |
Output is correct |
3 |
Correct |
171 ms |
17460 KB |
Output is correct |
4 |
Correct |
116 ms |
12384 KB |
Output is correct |
5 |
Correct |
103 ms |
12392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
5 ms |
468 KB |
Output is correct |
4 |
Correct |
3 ms |
564 KB |
Output is correct |
5 |
Correct |
5 ms |
596 KB |
Output is correct |
6 |
Correct |
5 ms |
596 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 |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
413 ms |
29440 KB |
Output is correct |
13 |
Correct |
407 ms |
29340 KB |
Output is correct |
14 |
Correct |
387 ms |
29456 KB |
Output is correct |
15 |
Correct |
392 ms |
29220 KB |
Output is correct |
16 |
Correct |
407 ms |
29312 KB |
Output is correct |
17 |
Correct |
32 ms |
3664 KB |
Output is correct |
18 |
Correct |
171 ms |
17460 KB |
Output is correct |
19 |
Correct |
116 ms |
12384 KB |
Output is correct |
20 |
Correct |
103 ms |
12392 KB |
Output is correct |
21 |
Correct |
96 ms |
7136 KB |
Output is correct |
22 |
Correct |
304 ms |
23892 KB |
Output is correct |
23 |
Correct |
205 ms |
14740 KB |
Output is correct |
24 |
Correct |
212 ms |
15036 KB |
Output is correct |