提交时间:2022-07-19 12:38:14

运行 ID: 52527

#include <iostream> #include <algorithm> #define ll long long using namespace std; const int P = 9973; const int MOD = 1000000007; inline int abs(int x) { if(x < 0) return -x; return x; } ll Hash(string s) { ll hash = 0; int n = s.size(); for(int i(0);i < n;i++) hash = (hash * P % MOD + (s[i] - 'a')) % MOD; return hash; } string Move(string s,int step) { int n = s.size(); string sub = s.substr(n - step,step); s.erase(n - step,step); s = sub + s; return s; } string R(string s,int x) { string sub = s.substr(0,x); s.erase(0,x); s = s + sub; reverse(s.begin(),s.end()); return s; } int main() { int T; cin>>T; while(T--) { string s,t; int a,b,k,n; ll h1,h2; bool OK = 0; cin>>s>>t>>a>>b; n = s.size(); k = abs(a - b); h1 = Hash(t); for(int i(1);i <= n;i++) { s = Move(s,k); h2 = Hash(s); if(h1 == h2||Hash(R(s,a)) == h1||Hash(R(s,b)) == h1) { OK = 1; cout<<"yes"<<endl; break; } } if(!OK) cout<<"no"<<endl; } return 0; }