Created
July 24, 2015 11:14
-
-
Save asdacap/b1b79d2cd1d117098b81 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<bits/stdc++.h> | |
using namespace std; | |
#define SET(t,v) memset((t), (v), sizeof(t)) | |
#define ALL(x) x.begin(), x.end() | |
#define UNIQUE(c) (c).resize( unique( ALL(c) ) - (c).begin() ) | |
#if __cplusplus > 199711L | |
#define ItREP(it,c) for(auto it = (c).begin(); it!= (c).end(); it++) | |
#define REP(i,n) for(decltype(n) i=0;i<n;i++) | |
#define IREP(in,i,n) for(decltype(n) i=in;i<n;i++) | |
#else | |
#define ItREP(it,c) for(typeof((c).begin()) it = (c).begin(); it!= (c).end(); it++) | |
#define REP(i,n) for(typeof(n) i=0;i<n;i++) | |
#define IREP(in,i,n) for(typeof(n) i=in;i<n;i++) | |
#endif | |
#define IN(a,b) ( (b).find(a) != (b).end()) | |
#define PB push_back | |
#define MP make_pair | |
typedef long long ll; | |
typedef long double LD; | |
typedef pair<int,int> pii; | |
#ifdef DEBUG | |
#define dbg(msg) msg | |
#define dbgp(msg) cerr << msg << endl; | |
#define var(v) cerr << #v << " = " << v << endl; | |
#else | |
#define dbg(msg) //msg | |
#define dbgp(msg) //cerr << msg << endl; | |
#define var(v) //cerr << #v << " = " << v << endl; | |
#endif | |
string astr,bstr; | |
int piisize(pii p){ | |
return p.second - p.first; | |
} | |
bool piieq(pii a,pii b){ | |
if(piisize(a) != piisize(b)){ | |
return false; | |
} | |
int i=0; | |
int size = piisize(a); | |
REP(i,size){ | |
if(astr[a.first+i] != bstr[b.first+i]) return false; | |
} | |
return true; | |
} | |
bool equavalent(pii a, pii b){ | |
if(piieq(a,b)){ | |
return true; | |
} | |
if(piisize(a) == piisize(b) && piisize(a) % 2 == 0){ | |
pii a1 = MP(a.first, (a.first+a.second)/2); | |
pii a2 = MP((a.first+a.second)/2, a.second); | |
pii b1 = MP(b.first, (b.first+b.second)/2); | |
pii b2 = MP((b.first+b.second)/2, b.second); | |
bool ans = ( equavalent(a1,b1) && equavalent(a2,b2) ) || | |
( equavalent(a2,b1) && equavalent(a1,b2) ); | |
return ans; | |
}else{ | |
return false; | |
} | |
} | |
int main(int argv, char** argc){ | |
cin.sync_with_stdio(0); | |
cin >> astr >> bstr; | |
if( equavalent(MP(0,astr.size()), MP(0,bstr.size())) ){ | |
printf("YES\n"); | |
}else{ | |
printf("NO\n"); | |
} | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment