Advertisement
SchrodZzz

with love xxx

Mar 17th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.39 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <fstream>
  5.  
  6. long long solve(std::string &top, std::string &bottom, std::string &left, std::string &right) {
  7.     long long ans = 0;
  8.     for (int i = 0; i + 1 < static_cast<int>(top.size()); ++i) {
  9.         for (int j = i + 1; j < static_cast<int>(top.size()); ++j) {
  10.             for (int shift = j - static_cast<int>(bottom.size()) + 1; shift <= i; shift++) {
  11.                 char c1 = bottom[i - shift];
  12.                 char c2 = bottom[j - shift];
  13.                 for (int l = 0; l + 1 < std::min<int>(static_cast<const int &>(left.size()),
  14.                                                       static_cast<const int &>(right.size())); ++l) {
  15.                     long long leftAns = 0;
  16.                     long long rightAns = 0;
  17.                     for (int k = 0; k + l + 1 < static_cast<int>(left.size()); ++k) {
  18.                         int tmp = k + l + 1;
  19.                         if (top[i] == left[k] && c1 == left[tmp]) {
  20.                             leftAns++;
  21.                         }
  22.                     }
  23.                     for (int k = 0; k + l + 1 < static_cast<int>(right.size()); ++k) {
  24.                         int tmp = k + l + 1;
  25.                         if (top[j] == right[k] && c2 == right[tmp]) {
  26.                             rightAns++;
  27.                         }
  28.                     }
  29.                     ans += leftAns * rightAns;
  30.                 }
  31.             }
  32.         }
  33.     }
  34.     return ans;
  35. }
  36.  
  37. int main() {
  38.     std::ifstream cin("crosswords.in");
  39.     std::ofstream cout("crosswords.out");
  40.     std::vector<std::string> words(4);
  41.     for (int i = 0; i < 4; ++i) {
  42.         cin >> words[i];
  43.     }
  44.     long long ans = 0;
  45.     for (int i = 0; i < 4; ++i) {
  46.         for (int j = i + 1; j < 4; ++j) {
  47.             std::vector<int> other(2);
  48.             int idx = 0;
  49.             for (int k = 0; k < 4; ++k) {
  50.                 if (k != i && k != j) {
  51.                     other[idx++] = k;
  52.                 }
  53.             }
  54.             int x = other[0];
  55.             int y = other[1];
  56.             ans += solve(words[i], words[j], words[x], words[y]) +
  57.                    solve(words[j], words[i], words[x], words[y]) +
  58.                    solve(words[i], words[j], words[y], words[x]) +
  59.                    solve(words[j], words[i], words[y], words[x]);
  60.         }
  61.     }
  62.     cout << ans << std::endl;
  63.     return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement