标签:
模拟判定就可以了
判定字符串是否相等用hash来判断
QAQ 值得一提的是一开始我交的时候T了
结果我将递归的顺序调整了一下就A了
(并不知道为什么
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
typedef unsigned long long LL;
const int maxn=200010;
const int x=13331;
int n;
char s[maxn];
char p[maxn];
LL xp[maxn],hs[maxn],hp[maxn];
bool cmp(int a,int b,int c,int d){
return hs[a]-hs[b+1]*xp[b-a+1]==hp[c]-hp[d+1]*xp[d-c+1];
}
bool Solve(int a,int b,int c,int d){
if(cmp(a,b,c,d))return true;
if((b-a+1)&1)return false;
int e=(a+b)>>1;
int f=(c+d)>>1;
if(Solve(a,e,f+1,d)&&Solve(e+1,b,c,f))return true;
if(Solve(a,e,c,f)&&Solve(e+1,b,f+1,d))return true;
return false;
}
int main(){
scanf("%s",s+1);scanf("%s",p+1);
n=strlen(s+1);
xp[0]=1;
for(int i=1;i<=n;++i)xp[i]=xp[i-1]*x;
hs[n+1]=0;hp[n+1]=0;
for(int i=n;i>=1;--i){
hs[i]=hs[i+1]*x+s[i]-‘a‘;
hp[i]=hp[i+1]*x+p[i]-‘a‘;
}
if(Solve(1,n,1,n))printf("YES\n");
else printf("NO\n");
return 0;
}
标签:
原文地址:http://www.cnblogs.com/joyouth/p/5371895.html