Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- //{
- //#pragma gcc optimize("Ofast,unroll-loops")
- //#pragma gcc target("sse,sse2,sse3,ssse3,sse4,avx,avx2,fma,abm,mmx,popcnt,tune=native")
- //#define int long long
- //#define double long double
- #define MP make_pair
- #define F first
- #define S second
- #define MOD 1000000007
- //}
- #define mys(c,n) ((((c) << ((n) % 7)) | ((c) >> (7 - ((n) % 7)))) & 127)
- string s;
- void solve(vector<char> &ans, vector<int> &mgc, int i, int x, int y)
- {
- if (i == s.size())
- if (ans[i - 1] == '!')
- {
- for (char &c : ans)
- cout << c;
- cout << '\n', exit(0);
- }
- char p, c;
- for (p = 32; p <= 126; p++)
- {
- c = mys(mys(p ^ x, i), mys(p ^ y, i)) ^ mys(mys(mgc[(p ^ x) & 3], i), mys(mgc[(p ^ y) & 3], i));
- if (s[i] == c)
- {
- ans.push_back(p);
- solve(ans, mgc, i + 1, p, c);
- ans.pop_back();
- }
- }
- }
- signed main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- getline(cin, s);
- vector<int> pos;
- for (int i = 0; i < 128; i++)
- {
- char c = mys(mys(65, 0), mys(65, 0)) ^ mys(mys(i, 0), mys(i, 0));
- if (c == s[0])
- pos.push_back(i);
- }
- vector<vector<int>> mgp;
- for (int &m1 : pos)
- for (int m0 = 0; m0 < 128; m0++)
- for (int m2 = 0; m2 < 128; m2++)
- for (int m3 = 0; m3 < 128; m3++)
- {
- bool ok = true;
- string S = "Ahoy!!";
- vector<int> mgc = {m0, m1, m2, m3};
- char p, c, x = 0, y = 0;
- for (int i = 0; i < S.size(); i++)
- {
- p = S[i];
- c = mys(mys(p ^ x, i), mys(p ^ y, i)) ^ mys(mys(mgc[(p ^ x) & 3], i), mys(mgc[(p ^ y) & 3], i));
- x = p;
- y = c;
- if (c != s[i])
- {
- ok = false;
- break;
- }
- }
- if (ok)
- mgp.push_back(mgc);
- }
- vector<char> ans = {'A', 'h', 'o', 'y', '!', '!'};
- for (auto &mgc : mgp)
- solve(ans, mgc, 6, '!', s[5]);
- return 0;
- }
- // ***** ***** * * * ***** * * ***** *****
- // * * * * * * * ** * * * *
- // * * * ***** * * * * * * *****
- // * * * * * * * * ** * *
- // **** ***** * ***** ***** * * * *
- // * * *** * * **
- // * * * * * * **
- // * * * ***** ***** **
- // * * * * * * *
- // * * * * * * **
Advertisement
Add Comment
Please, Sign In to add comment