QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#41210#4375. Stringyoungsystem#AC ✓936ms176980kbC++1.7kb2022-07-28 19:09:562022-07-28 19:09:59

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-07-28 19:09:59]
  • 评测
  • 测评结果:AC
  • 用时:936ms
  • 内存:176980kb
  • [2022-07-28 19:09:56]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<vector>
#include<bitset>
#include<algorithm>
#include<cstring>
#define mod 998244353
using namespace std;
inline int read()
{
	int n=0,f=1,ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		n=n*10+ch-'0';
		ch=getchar();
	}
	return n*f;
}
int nsl[1000005];
char s[1000005];
int kmp[1000005];
int fq[1000005],nson[1000005];
vector<int>v[1000005];
void dfs1(int x,int f)
{
	if(x==0)fq[x]=0;
	else
	{
		fq[x]=fq[f];
		while(2*nson[fq[x]]<=x)fq[x]=nson[fq[x]];
	}
	for(int i=0;i<v[x].size();i++)
	{
		if(v[x][i]==f)continue;
		nson[x]=v[x][i];
		dfs1(v[x][i],x);
	}
}
vector<int>gx[1000005];
int k;
int fsl[1000005];
void dfs2(int x,int f)
{
	if(x!=0)nsl[2*x%k]++;
	//printf("%lld %lld\n",x,nsl[x%k]);
	fsl[x]+=nsl[x%k];
	for(int i=0;i<gx[x].size();i++)fsl[gx[x][i]]-=nsl[gx[x][i]%k];
	for(int i=0;i<v[x].size();i++)
	{
		if(v[x][i]==f)continue;
		dfs2(v[x][i],x);
	}
	if(x!=0)nsl[2*x%k]--;
}
int main()
{
	int t,n;
	t=read();
	for(int greg=1;greg<=t;greg++)
	{
		scanf("%s",s+1);
		n=strlen(s+1);
		k=read();
		kmp[1]=0;
		int j=0;
		for(int i=2;i<=n;i++)
		{
			while(j>=1&&s[j+1]!=s[i])j=kmp[j];
			if(s[j+1]==s[i])j++;
			kmp[i]=j;
			//printf("%d %d\n",i,kmp[i]);
		}
		for(int i=0;i<=n;i++)v[i].clear(),gx[i].clear();
		for(int i=1;i<=n;i++)v[kmp[i]].push_back(i);
		dfs1(0,0);
		//for(int i=1;i<=n;i++)printf("%d %d\n",i,fq[i]);
		for(int i=0;i<=n;i++)fsl[i]=0; 
		for(int i=1;i<=n;i++)gx[fq[i]].push_back(i); 
		dfs2(0,0);
		int ans=1;
		for(int i=1;i<=n;i++)ans=1LL*ans*(fsl[i]+1)%mod;
		printf("%lld\n",ans);
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 936ms
memory: 176980kb

input:

10
kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk...

output:

811844748
106557744
583082277
750875845
539889742
198008691
286657978
344446711
612851418
36100066

result:

ok 10 lines