QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#283286#7754. Rolling For Daysgrass8cowWA 21ms19516kbC++141.9kb2023-12-14 12:14:522023-12-14 12:14:52

Judging History

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

  • [2023-12-14 12:14:52]
  • 评测
  • 测评结果:WA
  • 用时:21ms
  • 内存:19516kb
  • [2023-12-14 12:14:52]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int mod=998244353;
int qpow(int a,int b){
	int c=1;
	for(;b;b>>=1){
		if(b&1)c=1ll*a*c%mod;
		a=1ll*a*a%mod;
	}
	return c;
}
const int N=1e6;
int jc[N+10],ij[N+10],tp[N+10],inv[N+10];
void sieve(){
	jc[0]=1;
	for(int i=1;i<=N;i++)jc[i]=1ll*i*jc[i-1]%mod;
	ij[N]=qpow(jc[N],mod-2);
	for(int i=N;i;i--)ij[i-1]=1ll*i*ij[i]%mod;
	inv[1]=1;
	for(int i=2;i<=N;i++)inv[i]=mod-1ll*inv[mod%i]*(mod/i)%mod;
	for(int i=1;i<=N;i++)tp[i]=(tp[i-1]+inv[i])%mod; 
}
int C(int a,int b){
	if(a<b||a<0||b<0)return 0;
	return 1ll*jc[a]*ij[b]%mod*ij[a-b]%mod;
}
int n,m,a[20],b[20],ot[20];
int f[1<<12][1010],g[1<<12][1010];
int main(){
	sieve();
	scanf("%d%d",&n,&m);
	int pb=0;
	for(int i=0;i<m;i++)scanf("%d",&a[i]);
	for(int i=0;i<m;i++)scanf("%d",&b[i]),pb+=b[i],ot[i]=1ll*jc[a[i]]*ij[a[i]-b[i]]%mod;
	g[0][0]=1;
	for(int s=0;s<(1<<m);s++){
		int ts=0,bs=0;
		for(int i=0;i<m;i++)if((s>>i)&1)ts+=a[i]-b[i],bs+=b[i];
		for(int x=0;x<m;x++)if(!((s>>x)&1)){
			int s1=0,s2=0,s4=0;
			for(int i=0;i<=min(pb,n-ts);i++){
				if(i){
					int ob=1ll*jc[n-i-ts]*ot[x]%mod*C(i-1-bs,b[x]-1)%mod;
					(f[s|(1<<x)][i]+=1ll*ob*s1%mod)%=mod;
					(f[s|(1<<x)][i]+=1ll*ob*s2%mod*ts%mod)%=mod;
					(f[s|(1<<x)][i]-=1ll*ob*tp[n-i-ts]%mod*ts%mod*s4%mod)%=mod;
					(g[s|(1<<x)][i]+=1ll*ob*s4%mod)%=mod;
				}
				(s1+=1ll*ij[n-i-ts]*f[s][i]%mod)%=mod;
				(s2+=1ll*ij[n-i-ts]*g[s][i]%mod*tp[n-i-ts]%mod)%=mod; 
				(s4+=1ll*ij[n-i-ts]*g[s][i]%mod)%=mod;
			}
			/*for(int j=0;j<pb;j++)for(int i=1;i<=pb;i++)if(i+ts<=n){
				int xs=1ll*ot[x]*jc[n-i-ts]%mod*C(i-1-bs,b[x]-1)%mod*ij[n-j-ts]%mod;
				int fk=1ll*ts*(tp[n-j-ts]-tp[n-i-ts])%mod; 
				(f[s|(1<<x)][i]+=1ll*xs*f[s][j]%mod)%=mod;
				(f[s|(1<<x)][i]+=1ll*xs*fk%mod*g[s][j]%mod)%=mod;
				(g[s|(1<<x)][i]+=1ll*xs*g[s][j]%mod)%=mod;
			}*/
		}
	}
	printf("%d\n",((f[(1<<m)-1][pb]%mod+mod)%mod+pb)%mod);
	return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 14ms
memory: 19212kb

input:

2 2
1 1
1 1

output:

2

result:

ok answer is '2'

Test #2:

score: 0
Accepted
time: 21ms
memory: 19516kb

input:

4 2
2 2
2 1

output:

582309210

result:

ok answer is '582309210'

Test #3:

score: -100
Wrong Answer
time: 13ms
memory: 19488kb

input:

5 5
1 1 1 1 1
0 0 0 0 1

output:

1

result:

wrong answer expected '5', found '1'