fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. typedef long long ll;
  6. typedef pair<int, int> pii;
  7. typedef pair<ll, ll> pll;
  8. typedef vector<int> vi;
  9.  
  10. #define fi first
  11. #define se second
  12. #define pp push_back
  13. #define inarr(n, arr) for(int ax = 0; ax<(n); ax++)cin>>(arr)[ax];
  14. #define rep(aa, bb, cc) for(int aa = bb; aa < cc;aa++)
  15. #define all(x) (x).begin(), (x).end()
  16. #define allr(x) x.rbegin(),(x).rend()
  17. #define Ones(n) __builtin_popcount(n)
  18. #define endl '\n'
  19. #define yes cout<<"YES\n";
  20. #define no cout<<"NO\n";
  21. //#define int long long
  22.  
  23. void Gamal() {
  24. ios_base::sync_with_stdio(false);
  25. cin.tie(nullptr);
  26. cout.tie(nullptr);
  27. #ifdef Clion
  28. freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  29. #endif
  30. }
  31.  
  32. int dx[] = {+0, +0, -1, +1, +1, +1, -1, -1};
  33. int dy[] = {-1, +1, +0, +0, +1, -1, +1, -1};
  34.  
  35. const double EPS = 1e-9;
  36. const ll N = 2e5 + 5, INF = INT_MAX, MOD = 1e9 + 7, OO = 0X3F3F3F3F3F3F3F3F, LOG = 25;
  37.  
  38.  
  39. bool slv(string &a, string &b) {
  40. if (a == b)
  41. return true;
  42. if (a.size() % 2)
  43. return false;
  44. string a1 = a.substr(0, a.size() / 2);
  45. string a2 = a.substr(a.size() / 2, a.size() / 2);
  46. string b1 = b.substr(0, b.size() / 2);
  47. string b2 = b.substr(b.size() / 2, b.size() / 2);
  48. bool ret = slv(a1,b1) && slv(a2,b2);
  49. if(ret)return true;
  50. return slv(a1,b2) && slv(a2,b1);
  51. }
  52.  
  53. void solve() {
  54. string a, b;
  55. cin >> a >> b;
  56. cout << (slv(a, b) ? "YES" : "NO");
  57. }
  58.  
  59.  
  60. signed main() {
  61. Gamal();
  62. int t = 1;
  63. // cin >> t;
  64. while (t--) {
  65. solve();
  66. }
  67. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
YES