QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#152244#6328. Many ProductsForever_YoungML 7ms9004kbC++143.1kb2023-08-27 20:26:562023-08-27 20:26:58

Judging History

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

  • [2023-08-27 20:26:58]
  • 评测
  • 测评结果:ML
  • 用时:7ms
  • 内存:9004kb
  • [2023-08-27 20:26:56]
  • 提交

answer

#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int mo=998244353;
LL m;
int n,mf,res,a[200020],fac[200020],ifac[200020],dp[200020][44],sp[200020][44];
int fcc[200020][44][44];
vector<LL> f,pf;
int ksm(int x,int y){
	int res=1;
	while (y){
		if (y&1) res=1ll*res*x%mo;
		x=1ll*x*x%mo;
		y/=2;
	}
	return res;
}
void init(){
	int maxn=200002;
	fac[0]=1;
	for (int i=1;i<=maxn;i++) fac[i]=1ll*fac[i-1]*i%mo;
	ifac[maxn]=ksm(fac[maxn],mo-2);
	for (int i=maxn;i;i--) ifac[i-1]=1ll*ifac[i]*i%mo;
	//printf("gg\n");
	return;
}
void split(){
	for (int i=1;1ll*i*i<=m;i++)
	if (m%i==0){
		f.push_back(i);
		if (m/i!=i) f.push_back(m/i);
	}
	LL tmp=m;
	for (int i=2;1ll*i*i<=m;i++)
	if (tmp%i==0){
		pf.push_back(i);
		while (tmp%i==0) tmp/=i;
	}
	if (tmp!=1) pf.push_back(tmp); 
	//for (int i=0;i<pf.size();i++) printf("%lld\n",pf[i]);
	return;
}
LL c(int x,int y){//x>=y
	if (x<y) return 0;
	return 1ll*fac[x]*ifac[y]%mo*ifac[x-y]%mo;
}
void work(){
	int num[15],fm;
	LL tmp;
	sp[0][0]=1;
	for (int i=1;i<f.size();i++){
		sp[i][1]=1;
		memset(num,0,sizeof(num));
		tmp=f[i];
		//printf("%lld\n",tmp);
		for (int j=0;j<pf.size();j++){
			while (tmp%pf[j]==0){
				tmp/=pf[j];
				//printf("%lld %lld\n",tmp,pf[j]);
				num[j]++;
			}
		}
		//printf("gg\n");
		fm=1;
		while (sp[i][fm]!=0){
			sp[i][fm+1]=1;	
			for (int j=0;j<pf.size();j++)
				sp[i][fm+1]=sp[i][fm+1]*c(num[j]+fm,fm)%mo;
			for (int j=1;j<=fm;j++)
				sp[i][fm+1]=(sp[i][fm+1]-sp[i][j]*c(fm+1,j))%mo;
			sp[i][fm+1]=(sp[i][fm+1]+mo)%mo;
			fm+=1;
			//printf("%lld %d %d\n",f[i],fm,sp[i][fm]);
		}
		fm--;
		mf=max(mf,fm);
	}
	return;
}
int main(){
	scanf("%d%lld",&n,&m);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	init();
	split();
	work();
	fcc[0][0][0]=1;
	/*
	for (int i=0;i<f.size();i++){
		printf("%d:\n",f[i]);
		for (int j=1;j<=mf;j++) printf("	%d\n",sp[i][j]);
	}
	*/
	for (int i=1;i<=n;i++){
		fcc[i][0][0]=1ll*fcc[i-1][0][0]*(a[i]+1)%mo;
		for (int j=1;j<=mf;j++){
			fcc[i][j][0]=(1ll*fcc[i-1][j][0]*(a[i]+1)+1ll*fcc[i-1][j-1][0]*a[i])%mo;
			for (int k=1;k<=j;k++){
				fcc[i][j][k]=(1ll*fcc[i-1][j][k]*(a[i]+1)+1ll*fcc[i-1][j-1][k]*a[i]+1ll*fcc[i-1][j-1][k-1]*1)%mo;
			}
		}
	}
	/*
	for (int i=1;i<=n;i++){
		for (int j=0;j<=mf;j++) 
			for (int k=0;k<=j;k++) printf("%d %d %d %d\n",i,j,k,fcc[i][j][k]);
		printf("\n");
	}
	*/
	for (int i=1;i<=mf;i++){
		int tmp=0;
		tmp=1ll*fcc[n][i][0]*sp[1][i]%mo; //no pick
		//printf("%d\n",tmp);
		for (int j=1;j<=i;j++){
			/*
			for (int k=1;k<=n;k++) 
				tmp=(tmp+1ll*fcc[k-1][j-1]*c(n-k,i-j)%mo*ac[k+1]%mo)%mo;
			*/
			for (int k=0;k<f.size();k++){
				//printf("%d %d %d\n",k,j,sp[k][j]);
				//printf("%d %d %d\n",k^1,i-j,sp[k^1][i-j]);
				//printf("%lld\n",f[k]);
				if ((k^1)<f.size())
					tmp=(tmp+1ll*f[k]*sp[k][j]%mo*sp[k^1][i-j]%mo*fcc[n][i][j])%mo;
				else
					tmp=(tmp+1ll*f[k]*sp[k][j]%mo*sp[k][i-j]%mo*fcc[n][i][j])%mo;
				//printf("%d\n",tmp2);
				//printf("%lld\n",1ll*f[k]*sp[k][j]%mo*sp[k^1][i-j]%mo*fcc[n][i][j]);
			}
		}
		res=(res+tmp)%mo;
	}
	if (mf==0) res=fcc[n][0][0];
	printf("%d\n",res);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 8828kb

input:

2 3
0 1

output:

10

result:

ok 1 number(s): "10"

Test #2:

score: 0
Accepted
time: 0ms
memory: 7972kb

input:

5 1
0 1 2 3 4

output:

120

result:

ok 1 number(s): "120"

Test #3:

score: 0
Accepted
time: 7ms
memory: 9004kb

input:

10 314159265358
0 1 2 3 4 5 6 7 8 9

output:

658270849

result:

ok 1 number(s): "658270849"

Test #4:

score: -100
Memory Limit Exceeded

input:

200000 999999999989
823489320 406308599 710963770 183707427 192930969 941365774 318564299 391028855 945374838 651744270 515755727 220857626 599403217 214957584 335628890 771694833 40989299 34892948 630275822 869708185 432704750 924850167 707864789 232688853 406616372 529994171 782650336 979286144 65...

output:


result: