题意:定义了字符串的相等,问两串是否相等。
卡了时间,空间,不能新建字符串,否则会卡。
#pragma comment(linker,"/STACK:1024000000,1024000000") #include<iostream> #include<cstdio> #include<string> #include<cstring> #include<vector> #include<cmath> #include<queue> #include<stack> #include<map> #include<set> #include<algorithm> #include <stack> using namespace std; const int SZ=1e7+10,INF=0x7FFFFFFF; typedef long long lon; string x,y; bool cmp(int bg1,int end1,int bg2,int end2) { for(int i=bg1,j=bg2;i<end1;++i,++j) { if(x[i]!=y[j])return 1; } return 0; } bool equ(int bg1,int end1,int bg2,int end2,int d) { int len=end1-bg1; //cout<<d<<"cmp: "<<bg1<<" "<<end1<<" "<<bg2<<" "<<end2<<" "<<cmp(bg1,end1,bg2,end2)<<endl; if(cmp(bg1,end1,bg2,end2)==0)return 1; else if((len)&1)return 0; else { int half=len/2; return (equ(bg1,bg1+half,bg2,bg2+half,d+1)&&equ(bg1+half,end1,bg2+half,end2,d+1)||equ(bg1,bg1+half,bg2+half,end2,d+1)&&equ(bg1+half,end1,bg2,bg2+half,d+1)); } } int main() { std::ios::sync_with_stdio(0); cin>>x>>y; if(equ(0,x.size(),0,y.size(),0))cout<<"YES"<<endl; else cout<<"NO"<<endl; return 0; }