提交时间:2022-07-19 13:13:06
运行 ID: 52572
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define ll unsigned long long using namespace std; int t,n=500000,x,y,g,flag; int base[500005]; char s1[500005],s2[500005]; int h1[500005],h2[500005]; ll H1(int l,int r){ return h1[r]-h1[l-1]*base[r-l+1]; } ll H2(int l,int r){ return h2[r]-h2[l-1]*base[r-l+1]; } int gcd(int a,int b){ return b?gcd(b,a%b):a; } int main(){ scanf("%d",&t); base[0]=1; base[1]=13331; for(int i=2;i<=n;i+=1){ base[i]=base[i-1]*base[1]; } while(t--){ scanf("%s%s",s1+1,s2+1); scanf("%d%d",&x,&y); if(x>y) swap(x,y); n=strlen(s1+1); g=gcd(y-x,n); flag=0; for(int i=1;i<=n;i+=1){ h1[i]=h1[i-1]*base[1]+s1[i]; h2[i]=h2[i-1]*base[1]+s2[i]; } for(int i=0;i<n;i+=1){ if(H1(i+1,n)==H2(1,n-i)&&H1(1,i)==H2(n-i+1,n)){ if(i%g) continue; flag=1; break; } } if(flag){ printf("yes\n"); continue; } reverse(s1+1,s1+x+1); reverse(s1+x+1,s1+n+1); for(int i=1;i<=n;i+=1){ h1[i]=h1[i-1]*base[1]+s1[i]; } for(int i=0;i<n;i+=1){ if(H1(i+1,n)==H2(1,n-i)&&H1(1,i)==H2(n-i+1,n)){ if(i%g) continue; flag=1; break; } } if(flag) printf("yes\n"); else printf("no\n"); } return 0; }