Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
52255 AK2022071346 修复符文 C++ 通过 100 87 MS 4584 KB 1540 2022-07-19 11:51:14

Tests(20/20):


#include<cstdio> #include<string> #include<cstring> #include<iostream> #define int long long using namespace std; int T,a,b,x,n,m=1e9+7,p[500501],hsh1,hsh2,hsh3,ans; string s1,s2; char s3[500501]; int g(int x,int y) { if(x<y)swap(x,y); if(x%y==0)return y; return g(y,x%y); } bool pd(int z,int x,int y) { if(y==0)return 1; int ff=g(z,x); if(y%ff==0)return 1; return 0; } signed main() { scanf("%lld",&T); p[0]=1; for(int i=1;i<=500000;i++)p[i]=(p[i-1]*26)%m; while(T--) { hsh1=hsh2=hsh3=ans=0; cin>>s1; cin>>s2; scanf("%lld%lld",&a,&b); if(a<b)swap(a,b); x=a-b; n=s1.size(); for(int i=0;i<n;i++) { hsh1=(hsh1+(p[i]*(s1[n-i-1]-'a')))%m; hsh2=(hsh2+(p[i]*(s2[n-i-1]-'a')))%m; } for(int i=0;i<=n;i++) { if(hsh1==hsh2) { if(pd(n,x,i)) { printf("yes\n"); ans=1; break; } } if(i==n)break; hsh1-=p[n-1]*(s1[i]-'a'); while(hsh1<0)hsh1+=m; hsh1%=m; hsh1*=26; hsh1+=s1[i]-'a'; hsh1%=m; } if(ans)continue; for(int i=b-1;i>=0;i--)s3[b-1-i]=s1[i]; for(int i=n-1;i>=b;i--)s3[n-1-i+b]=s1[i]; for(int i=0;i<n;i++) hsh3=(hsh3+(p[i]*(s3[n-i-1]-'a')))%m; for(int i=0;i<=n;i++) { if(hsh3==hsh2) { if(pd(n,x,i)) { printf("yes\n"); ans=1; break; } } if(i==n)break; hsh3-=p[n-1]*(s3[i]-'a'); while(hsh3<0)hsh3+=m; hsh3%=m; hsh3*=26; hsh3+=s3[i]-'a'; hsh3%=m; } if(!ans)printf("no\n"); } return 0; }


测评信息: