fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. bool ms(string a,string b,ll s1,ll s2,ll e1,ll e2){
  5. if(s1>e1 || s2>e2)
  6. return false;
  7. ll index=s2;
  8. for(ll i=s1;i<=e1;i++){
  9. if(a[i]!=b[index]){
  10. index=-1;
  11. break;
  12. }
  13. index++;
  14. }
  15. if(index!=-1)
  16. return true;
  17. if((e1-s1+1)%2==1 || (e2-s2+1)%2==1){
  18. return false;
  19. }
  20. ll mid1=(s1+e1)/2;
  21. ll mid2=(s2+e2)/2;
  22. return (ms(a,b,s1,s2,mid1,mid2)&& ms(a,b,mid1+1,mid2+1,e1,e2))||(ms(a,b,s1,mid2+1,mid1,e2)&& ms(a,b,mid1+1,s2,e1,mid2));
  23.  
  24. }
  25. bool solve(string a,string b,ll s1,ll s2,ll e1,ll e2){
  26. ll mid=(s1+e1)/2;
  27. return (ms(a,b,s1,s2,mid,mid)&& ms(a,b,mid+1,mid+1,e1,e2))||(ms(a,b,s1,mid+1,mid,e2)&& ms(a,b,mid+1,s2,e1,mid));
  28.  
  29. }
  30. int main(){
  31. ios_base::sync_with_stdio(false);
  32. cin.tie(NULL);
  33. string a,b;
  34. cin>>a>>b;
  35. if(a==b)
  36. cout<<"YES\n";
  37. else{
  38. ll l1=a.length();
  39. ll l2=b.length();
  40. if(l1!=l2){
  41. cout<<"NO\n";
  42. }
  43. else{
  44. if(l1%2==1)
  45. cout<<"NO\n";
  46. else if(solve(a,b,0,0,l1-1,l2-1)){
  47. cout<<"YES\n";
  48. }
  49. else{
  50. cout<<"NO\n";
  51. }
  52. }
  53. }
  54.  
  55. return 0;
  56. }
  57.  
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
YES