Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ┓┏┓┏┓┃
- ┛┗┛┗┛┃
- ┓┏┓┏┓┃
- ┛┗┛┗┛┃
- ┓┏┓┏┓┃\○/
- ┛┗┛┗┛┃ / /
- ┓┏┓┏┓┃ノ
- ┛┗┛┗┛┃
- ┓┏┓┏┓┃
- ┛┗┛┗┛┃
- ┓┏┓┏┓┃
- ┛┗┛┗┛┃
- ┓┏┓┏┓┃
- ┛┗┛┗┛┃
- ┓┏┓┏┓┃┓
- ┛┗┛┗┛┃┃
- MIPTCLASSICMIPTCLASSICMIPTCLASSICMIPTCLASSICMIPTCLASSICMIPTCLASSIC
- */
- #define pragma
- #ifdef pragma
- #pragma GCC optimize("Ofast")
- #pragma GCC optimize("no-stack-protector")
- #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
- #pragma GCC optimize("unroll-loops")
- #pragma GCC diagnostic ignored "-Wunused-result"
- #endif // pragma
- #include<bits/stdc++.h>
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- #define ll long long
- #define all(x) begin(x), end(x)
- #define pb push_back
- #define x first
- #define y second
- #define int long long
- #define zero(two) memset(two, 0, sizeof(two))
- using namespace std;
- using namespace __gnu_pbds;
- typedef vector<int> vi;
- typedef vector<bool> vb;
- typedef pair<int, int> pii;
- typedef long double ld;
- typedef vector<vi> matrix;
- template<typename T>
- using kawaii_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
- const ld PI = atan2(0, -1);
- void seriy() {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- cout << fixed << setprecision(10);
- #if _offline
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- }
- const int BASE = 47;
- const int MOD = 998244353;
- const int MAXN = 2e5 + 10;
- vi pows(MAXN);
- vi sh, th;
- string s, t;
- vi get_hash(string &s) {
- int n = s.size() + 1;
- vi h(n);
- for(int i = 1; i < n; i++) {
- h[i] = (h[i - 1] + s[i - 1] * pows[i]) % MOD;
- }
- return h;
- }
- int subhash(vi &h, int l, int r) {
- return ((h[r] - h[l - 1] + MOD) * pows[h.size() - l]) % MOD;
- }
- bool equals(int tl, int tr, int l, int r) {
- if(subhash(sh, tl + 1, tr + 1) == subhash(th, l + 1, r + 1)) {
- return 1;
- }
- if((tr - tl + 1) & 1) {
- return 0;
- }
- int tm = (tl + tr) >> 1;
- int m = (l + r) >> 1;
- return equals(tl, tm, l, m) && equals(tm + 1, tr, m + 1, r) || equals(tl, tm, m + 1, r) && equals(tm + 1, tr, l, m);
- }
- signed main() {
- seriy();
- cin >> s >> t;
- pows[0] = 1;
- for(int i = 1; i < MAXN; i++) {
- pows[i] = pows[i - 1] * BASE;
- pows[i] %= MOD;
- }
- sh = get_hash(s);
- th = get_hash(t);
- cout << ((equals(0, s.size() - 1, 0, t.size() - 1)) ? "YES" : "NO");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment