QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#190167#6851. Cyclically IsomorphicmasterhuangAC ✓23ms34900kbC++201.1kb2023-09-28 14:01:152023-09-28 14:01:15

Judging History

你现在查看的是最新测评结果

  • [2023-09-28 14:01:15]
  • 评测
  • 测评结果:AC
  • 用时:23ms
  • 内存:34900kb
  • [2023-09-28 14:01:15]
  • 提交

answer

#include<bits/stdc++.h>
#define LL long long
#define P pair<int,int>
#define fi first
#define se second
#define fr(x) freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);
using namespace std;
inline string rds()
{
	string x="";char ch=getchar();
	while(ch<'a'||ch>'z') ch=getchar();
	while(ch>='a'&&ch<='z') x+=ch,ch=getchar();
	return x;
}
inline int rd()
{
	int x=0;char ch=getchar();
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x;
}
const int N=1e6+5,mod=998244353;
int T,n,m,q,pw[N],a[N];string c[N];
inline int md(int x){return x>=mod?x-mod:x;}
int main()
{
	T=rd();
	while(T--)
	{
		n=rd(),m=rd();for(int i=1;i<=n;i++) c[i]=rds();q=rd();
		for(int i=pw[0]=1;i<=m;i++) pw[i]=28ll*pw[i-1]%mod;
		for(int i=1;i<=n;i++)
		{
			int S=0;
			for(int j=0;j<m;j++) S=(S+1ll*pw[m-1-j]*(c[i][j]-'a'+1))%mod;
			a[i]=S;
			for(int j=0;j<m-1;j++)
			{
				S=(S-1ll*pw[m-1]*(c[i][j]-'a'+1))%mod;S=md(S+mod);
				S=(28ll*S+(c[i][j]-'a'+1))%mod;a[i]=min(a[i],S);
			}
		}int x,y;
		while(q--) x=rd(),y=rd(),puts((a[x]==a[y])?"Yes":"No");	
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 23ms
memory: 34900kb

input:

5
10 10000
afcadffafeeebdfedfdafecfdbeecbcadfedcffaedecbacffedeccacfcbfbbdbcefbdefefebcbeacfbaafddbabcbfaeddaaefebbddafaaaaaedcbbdaafaffcbeeebfbbeedebabfbdbaceabfcccfedbdeafccbaffdeadbefbfeadbbedeeabbaafebaceeaeedbaddfecdefaabdbcfadadaebbdeedcfeeabbbdbcefdadbeecafcabbddddbcacadbbcddeddbbeecbdadefbaa...

output:

No
No
No
Yes
Yes
No
No
No
Yes
No
No
No
No
No
No
No
No
No
No
No
No
No
Yes
No
No
No
No
No
No
No
No
No
No
Yes
No
No
No
Yes
No
No
No
No
No
No
No
No
Yes
No
Yes
No
No
No
No
No
Yes
No
No
No
No
No
No
No
No
No
Yes
No
No
Yes
No
No
No
No
No
No
No
No
No
No
No
Yes
No
Yes
No
Yes
No
No
No
No
No
No
No
No
Yes
Yes
Ye...

result:

ok 500000 lines