提交时间:2022-07-19 11:52:32
运行 ID: 52316
#include<bits/stdc++.h> using namespace std; #define ll unsigned long long const ll has=131; inline int read(){ int X=0,w=0; char ch=0; while(!isdigit(ch)) {w|=ch=='-';ch=getchar();} while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar(); return w?-X:X; } inline void write(int x){ if(x<0) putchar('-'),x=-x; if(x>9) write(x/10); putchar(x%10+'0'); } int a,b; string s,t; string s1,s2; ll ha[1000001],ha1[1000001],ha2[1000001]; ll pre1[1000001]; ll get(ll h[],int l,int r){ return h[r]-h[l-1]*pre1[r-l+1]; } ll res; bool check(int l,int r){ if(get(ha,l,r)==res||get(ha1,l,r)==res||get(ha2,l,r)==res) return 1; return 0; } int main(){ int T=read(); while(T--){ cin>>s>>t>>a>>b; int n=s.size(); s1=s.substr(a)+s.substr(0,a); reverse(s1.begin(),s1.end()); s2=s.substr(b)+s.substr(0,b); reverse(s2.begin(),s2.end()); s=s+s; s='#'+s; s1=s1+s1; s1='#'+s1; s2=s2+s2; s2='#'+s2; t='#'+t; ha[0]=ha1[0]=ha2[0]=0; pre1[0]=1; res=0; for(int i=1;i<=2*n;i++){ pre1[i]=pre1[i-1]*has; ha[i]=ha[i-1]*has+s[i]-'a'+1; ha1[i]=ha1[i-1]*has+s1[i]-'a'+1; ha2[i]=ha2[i-1]*has+s2[i]-'a'+1; if(i<=n) res=res*has+t[i]-'a'+1; } if(a<b) swap(a,b); int l=1; bool fl=0; for(int i=1;i<=n;i++){ if(check(l,l+n-1)){ fl=1; break; } l=l+n-a+b; if(l>n) l=l%(n+1)+1; } if(fl==1){ puts("yes"); continue; } l=1; for(int i=1;i<=n;i++){ if(check(l,l+n-1)){ fl=1; break; } l=l+a-b; if(l>n) l=l%(n+1)+1; } if(fl) puts("yes"); else puts("no"); } return 0; }