joylintp

Untitled

Apr 30th, 2022
1,367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.81 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. //{
  5. //#pragma gcc optimize("Ofast,unroll-loops")
  6. //#pragma gcc target("sse,sse2,sse3,ssse3,sse4,avx,avx2,fma,abm,mmx,popcnt,tune=native")
  7. //#define int long long
  8. //#define double long double
  9. #define MP make_pair
  10. #define F first
  11. #define S second
  12. #define MOD 1000000007
  13. //}
  14.  
  15. #define mys(c,n) ((((c) << ((n) % 7)) | ((c) >> (7 - ((n) % 7)))) & 127)
  16.  
  17. string s;
  18.  
  19. void solve(vector<char> &ans, vector<int> &mgc, int i, int x, int y)
  20. {
  21.     if (i == s.size())
  22.         if (ans[i - 1] == '!')
  23.         {
  24.             for (char &c : ans)
  25.                 cout << c;
  26.             cout << '\n', exit(0);
  27.         }
  28.  
  29.     char p, c;
  30.     for (p = 32; p <= 126; p++)
  31.     {
  32.         c = mys(mys(p ^ x, i), mys(p ^ y, i)) ^ mys(mys(mgc[(p ^ x) & 3], i), mys(mgc[(p ^ y) & 3], i));
  33.         if (s[i] == c)
  34.         {
  35.             ans.push_back(p);
  36.             solve(ans, mgc, i + 1, p, c);
  37.             ans.pop_back();
  38.         }
  39.     }
  40. }
  41.  
  42. signed main()
  43. {
  44.     ios_base::sync_with_stdio(false);
  45.     cin.tie(0);
  46.  
  47.     getline(cin, s);
  48.  
  49.     vector<int> pos;
  50.     for (int i = 0; i < 128; i++)
  51.     {
  52.         char c = mys(mys(65, 0), mys(65, 0)) ^ mys(mys(i, 0), mys(i, 0));
  53.         if (c == s[0])
  54.             pos.push_back(i);
  55.     }
  56.  
  57.     vector<vector<int>> mgp;
  58.     for (int &m1 : pos)
  59.         for (int m0 = 0; m0 < 128; m0++)
  60.             for (int m2 = 0; m2 < 128; m2++)
  61.                 for (int m3 = 0; m3 < 128; m3++)
  62.                 {
  63.                     bool ok = true;
  64.                     string S = "Ahoy!!";
  65.                     vector<int> mgc = {m0, m1, m2, m3};
  66.                     char p, c, x = 0, y = 0;
  67.                     for (int i = 0; i < S.size(); i++)
  68.                     {
  69.                         p = S[i];
  70.                         c = mys(mys(p ^ x, i), mys(p ^ y, i)) ^ mys(mys(mgc[(p ^ x) & 3], i), mys(mgc[(p ^ y) & 3], i));
  71.                         x = p;
  72.                         y = c;
  73.                         if (c != s[i])
  74.                         {
  75.                             ok = false;
  76.                             break;
  77.                         }
  78.                     }
  79.  
  80.                     if (ok)
  81.                         mgp.push_back(mgc);
  82.                 }
  83.  
  84.     vector<char> ans = {'A', 'h', 'o', 'y', '!', '!'};
  85.     for (auto &mgc : mgp)
  86.         solve(ans, mgc, 6, '!', s[5]);
  87.  
  88.     return 0;
  89. }
  90.  
  91. //      *****  *****  *   *  *      *****  *   *  *****  *****
  92. //        *   *   *  *   *  *        *    **  *    *    *   *
  93. //       *   *   *  *****  *        *    * * *    *    *****
  94. //   *  *   *   *    *    *        *    *  **    *    *
  95. //  ****   *****    *    *****  *****  *   *    *    *
  96.  
  97. //     *   *   ***   *   *  **
  98. //    *   *  *   *  *   *  **
  99. //   * * *  *****  *****  **
  100. //  * * *  *   *  *   *
  101. //  * *   *   *  *   *  **
  102.  
Advertisement
Add Comment
Please, Sign In to add comment