fork download
  1. #include <string>
  2. #include <vector>
  3. #include <iostream>
  4. #include <unordered_set>
  5. using namespace std;
  6. inline int hashing(string s) {
  7. return int(s[0] - 'A') * 26 * 26 * 26 + int(s[1] - 'A') * 26 * 26 + int(s[2] - 'A') * 26 + int(s[3] - 'A');
  8. }
  9. int main() {
  10. cin.tie(0);
  11. ios_base::sync_with_stdio(false);
  12. int N;
  13. cin >> N;
  14. vector<vector<int> > gl(676), gr(676), gu(676), gd(676);
  15. vector<string> s(N);
  16. vector<bool> st(676 * 676);
  17. for (int i = 0; i < N; ++i) {
  18. string sa, sb;
  19. cin >> sa >> sb;
  20. s[i] = sa + sb;
  21. int cu = int(s[i][0] - 'A') * 26 + int(s[i][1] - 'A');
  22. int cd = int(s[i][2] - 'A') * 26 + int(s[i][3] - 'A');
  23. int cl = int(s[i][0] - 'A') * 26 + int(s[i][2] - 'A');
  24. int cr = int(s[i][1] - 'A') * 26 + int(s[i][3] - 'A');
  25. gu[cu].push_back(cd);
  26. gd[cd].push_back(cu);
  27. gl[cl].push_back(cr);
  28. gr[cr].push_back(cl);
  29. st[hashing(s[i])] = true;
  30. }
  31. int ans = 0;
  32. for (int i = 0; i < 676; ++i) {
  33. vector<int> va = gl[i], vb = gr[i];
  34. ans += va.size() * vb.size();
  35. vector<bool> fa(676), fb(676);
  36. for (int j : va) fa[j] = true;
  37. for (int j : vb) fb[j] = true;
  38. if (fa[i] && fb[i]) --ans;
  39. }
  40. for (int i = 0; i < 676; ++i) {
  41. vector<int> va = gu[i], vb = gd[i];
  42. ans += va.size() * vb.size();
  43. vector<bool> fa(676), fb(676);
  44. for (int j : va) fa[j] = true;
  45. for (int j : vb) fb[j] = true;
  46. if (fa[i] && fb[i]) --ans;
  47. }
  48. int twos = 0, fours = 0;
  49. for (int i = 0; i < N; ++i) {
  50. string opp1 = string(1, s[i][2]) + string(1, s[i][3]) + string(1, s[i][0]) + string(1, s[i][1]);
  51. string opp2 = string(1, s[i][1]) + string(1, s[i][0]) + string(1, s[i][3]) + string(1, s[i][2]);
  52. if (s[i] != opp1 && st[hashing(opp1)]) ++twos;
  53. if (s[i] != opp2 && st[hashing(opp2)]) ++twos;
  54. if (s[i][1] == s[i][2]) {
  55. for (char c = 'A'; c <= 'Z'; ++c) {
  56. string opp3 = string(1, c) + string(1, s[i][0]) + string(1, s[i][0]) + string(1, s[i][1]);
  57. string opp4 = string(1, s[i][2]) + string(1, s[i][3]) + string(1, s[i][3]) + string(1, c);
  58. if (s[i] != opp3 && st[hashing(opp3)]) ++twos;
  59. if (s[i] != opp4 && st[hashing(opp4)]) ++twos;
  60. }
  61. }
  62. if (s[i][0] == s[i][3]) {
  63. for (char c = 'A'; c <= 'Z'; ++c) {
  64. string opp3 = string(1, s[i][1]) + string(1, c) + string(1, s[i][0]) + string(1, s[i][1]);
  65. string opp4 = string(1, s[i][2]) + string(1, s[i][3]) + string(1, c) + string(1, s[i][2]);
  66. if (s[i] != opp3 && st[hashing(opp3)]) ++twos;
  67. if (s[i] != opp4 && st[hashing(opp4)]) ++twos;
  68. }
  69. }
  70. if (s[i][0] == s[i][3] && s[i][1] == s[i][2]) {
  71. string opp5 = string(1, s[i][1]) + string(1, s[i][0]) + string(1, s[i][0]) + string(1, s[i][1]);
  72. if (s[i] != opp5 && st[hashing(opp5)]) ++fours;
  73. }
  74. }
  75. twos /= 2;
  76. fours /= 2;
  77. cout << ans - twos + fours * 3 << endl;
  78. return 0;
  79. }
Runtime error #stdin #stdout 0s 15736KB
stdin
Standard input is empty
stdout
Standard output is empty