Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
52439 AK2022071341 修复符文 C++ 运行超时 20 2009 MS 8280 KB 2113 2022-07-19 12:11:51

Tests(4/20):


#include<bits/stdc++.h> #define ll long long using namespace std; const ll mod1=998244353; const ll mod2=1e9+7; const ll base=26; const int N=5e5+10; int T; char s[N],t[N]; ll pow1[N],pow2[N]; inline int gcd(int a,int b){ return b?gcd(b,a%b):a; } inline ll hsh1(char *a,int len){ ll res=0; for(int i=1,j=len-1;i<=len;i++,j--)res=(res+(a[i]-'a')*pow1[j])%mod1; return res; } inline ll hsh2(char *a,int len){ ll res=0; for(int i=1,j=len-1;i<=len;i++,j--)res=(res+(a[i]-'a')*pow2[j])%mod2; return res; } inline ll change1(ll cur,int New,int k,int len){ for(int i=New-k,j=len-1;i<New;i++,j--)cur=((cur-(s[i]-'a')*pow1[j])%mod1+mod1)%mod1; cur=cur*pow1[k]%mod1; for(int i=New-k,j=k-1;i<New;i++,j--)cur=(cur+(s[i]-'a')*pow1[j])%mod1; return cur; } inline ll change2(ll cur,int New,int k,int len){ for(int i=New-k,j=len-1;i<New;i++,j--)cur=((cur-(s[i]-'a')*pow2[j])%mod2+mod2)%mod2; cur=cur*pow2[k]%mod2; for(int i=New-k,j=k-1;i<New;i++,j--)cur=(cur+(s[i]-'a')*pow2[j])%mod2; return cur; } int main(){ scanf("%d",&T); pow1[0]=pow2[0]=1; for(int i=1;i<N;i++){ pow1[i]=pow1[i-1]*base%mod1; pow2[i]=pow2[i-1]*base%mod2; } while(T--){ int a,b; scanf("%s",s+1); scanf("%s",t+1); scanf("%d%d",&a,&b); int len=strlen(s+1); int k=gcd(b-a,len); ll ans1=hsh1(t,len); ll ans2=hsh2(t,len); ll cur1=hsh1(s,len); ll cur2=hsh2(s,len); if(ans1==cur1&&ans2==cur2){ puts("yes"); continue; } bool flag=0; for(int i=k+1;i<=len;i+=k){ cur1=change1(cur1,i,k,len); cur2=change2(cur2,i,k,len); if(ans1==cur1&&ans2==cur2){ puts("yes"); flag=1; break; } } for(int i=1;i<=(a>>1);i++)swap(s[i],s[a-i+1]); for(int i=1;i<=(len-a)>>1;i++)swap(s[i+a],s[len-i+1]); cur1=hsh1(s,len); cur2=hsh2(s,len); if(ans1==cur1&&ans2==cur2){ puts("yes"); continue; } for(int i=k+1;i<=len;i+=k){ cur1=change1(cur1,i,k,len); cur2=change2(cur2,i,k,len); if(ans1==cur1&&ans2==cur2){ puts("yes"); flag=1; break; } } if(!flag)puts("no"); } return 0; }


测评信息: