运气不错,这次cf大涨,居然是房间第二(要不是D题TLE了,就第一了)
用string会TLE,用char加下标,还看到更牛的算法,
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 using namespace std; 5 const int maxx=200010; 6 char a[maxx],b[maxx]; 7 bool cmp(int p1,int p2,int len) 8 { 9 for(int i=0;i<len;i++) 10 if(a[i+p1]!=b[i+p2]) return 0; 11 return 1; 12 } 13 bool judge(int p1,int p2,int len) 14 { 15 bool flag=cmp(p1,p2,len); 16 if(flag==1) return 1; 17 if(len&1) return 0; 18 len/=2; 19 if(((judge(p1,p2,len))&&(judge(p1+len,p2+len,len))) 20 ||(judge(p1,p2+len,len)&&judge(p1+len,p2,len))) 21 return 1; 22 return 0; 23 } 24 int main() 25 { 26 scanf("%s%s",a,b); 27 if(judge(0,0,strlen(a))) printf("YES "); 28 else printf("NO "); 29 }
最近有点忙,就不瞎写了
1 #include<bits/stdc++.h> 2 using namespace std; 3 string gosort (string s) 4 { 5 if (s.size () % 2) return s ; 6 string s1 = gosort (s.substr (0 , s.size () / 2 )) ; 7 string s2 = gosort (s.substr (s.size () / 2 , s.size () )) ; 8 if (s1 < s2) return s1 + s2 ; 9 else return s2 + s1 ; 10 } 11 int main () 12 { 13 string a , b ; 14 cin >> a >> b ; 15 if (gosort (a) == gosort (b)) puts ("YES") ; 16 else puts ("NO") ; 17 return 0 ; 18 }