QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#404924#7754. Rolling For DaysSorting#WA 9ms38376kbC++201.8kb2024-05-05 01:09:272024-05-05 01:09:28

Judging History

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

  • [2024-05-05 01:09:28]
  • 评测
  • 测评结果:WA
  • 用时:9ms
  • 内存:38376kb
  • [2024-05-05 01:09:27]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=998244353;
int n,m;
const int iu=2000;
ll f[2005],inf[2005];
ll C[2005][2005];
ll pw(ll x,ll y){
	if(y==0) return 1;
	if(y%2) return x*pw(x,y-1)%mod;
	ll res=pw(x,y/2);
	return res*res%mod;
}
int a[15],b[15];
ll ff[4096][1005];
int deg[4096];
ll dp[4096][1005];
int main(){
	ios::sync_with_stdio(false);cin.tie(0);
	cin >> n >> m;
	for(int i=0; i<m ;i++) cin >> a[i];
	for(int i=0; i<m ;i++) cin >> b[i];
	C[0][0]=1;f[0]=inf[0]=1;
	for(int i=1; i<=iu ;i++){
		f[i]=f[i-1]*i%mod;
		inf[i]=pw(f[i],mod-2);
		C[i][0]=1;
		for(int j=1; j<=i ;j++) C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
	}
	ff[0][0]=1;
	deg[0]=0;
	for(int i=1; i<(1<<m) ;i++){
		int w=i&-i;
		int g=0;
		while(w!=(1<<g)) ++g;
		deg[i]=deg[i^w]+b[g]-1;
		for(int j=0; j<=deg[i^w] ;j++){
			for(int k=0; k<b[g] ;k++){
				ff[i][j+k]=(ff[i][j+k]+ff[i^w][j]*C[a[g]][k])%mod;
			}
		}
	}
	dp[0][0]=1;
	ll ans=0;
	for(int i=0; i<(1<<m)-1 ;i++){
		for(int j=0; j<=n ;j++){
			if(dp[i][j]==0) continue;
			int can=0;
			int trash=0;
			int done=0;
			for(int k=0; k<m ;k++){
				if((i>>k)&1) trash+=a[k]-b[k],done+=b[k];
				else can+=a[k];
			}
			can-=j-done;
			ll cost=(trash*f[can-1]%mod*inf[can]%mod+1);
			ans=(ans+cost*dp[i][j])%mod;
			ll ways=1;
			int mask=((1<<m)-1)^i;
			for(int k=0; k<m ;k++){//calculate ways to complete set k
				if((i>>k)&1) continue;
				int g=k;
				if(j-done<b[g]-1) continue;
				ll num=ff[mask^(1<<k)][j-done-b[g]+1]*C[a[g]][b[g]-1]%mod;
				ll den=ff[mask][j-done];
				ll prob=(a[g]-b[g]+1)*f[can-1]%mod*inf[can]%mod;
				
				prob=num*prob%mod*pw(den,mod-2)%mod;
				dp[i|(1<<k)][j+1]=(dp[i|(1<<k)][j+1]+prob*dp[i][j])%mod;
				ways=(ways+mod-prob)%mod;
			}
			dp[i][j+1]=(dp[i][j+1]+dp[i][j]*ways)%mod;
		}
	}
	cout << ans << '\n';
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 37548kb

input:

2 2
1 1
1 1

output:

2

result:

ok answer is '2'

Test #2:

score: 0
Accepted
time: 9ms
memory: 37236kb

input:

4 2
2 2
2 1

output:

582309210

result:

ok answer is '582309210'

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 38376kb

input:

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

output:

6

result:

wrong answer expected '5', found '6'