QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#404937#7754. Rolling For DaysSortingWA 0ms38120kbC++202.1kb2024-05-05 01:31:162024-05-05 01:31:18

Judging History

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

  • [2024-05-05 01:31:18]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:38120kb
  • [2024-05-05 01:31:16]
  • 提交

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 fast_mod(ll x){
    return (x >= mod) ? (x - mod) : x;
}

inline ll pw(ll x,ll y){
    ll res = 1;
    while(y) {
        if(y & 1) {
            res = fast_mod(res * x);
        }
        x = fast_mod(x * x);
        y >>= 1;
    }
    return res;
}
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];
	int ST=0;
	for(int i=0; i<m ;i++){
		cin >> b[i];
		if(b[i]==0) ST|=1<<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++){
		if(i&ST) continue;
		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[ST][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';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 38120kb

input:

2 2
1 1
1 1

output:

3

result:

wrong answer expected '2', found '3'