QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#722295#7754. Rolling For DaysxzzduangWA 1ms5744kbC++232.0kb2024-11-07 18:30:282024-11-07 18:30:29

Judging History

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

  • [2024-11-07 18:30:29]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5744kb
  • [2024-11-07 18:30:28]
  • 提交

answer

#include<iostream>
#include<stdio.h>
#include<ctype.h>
#include<string.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define int long long
#define pii pair<int,int>
#define lowbit(x) ((x)&-(x))
#define popcount(x) __builtin_popcount(x)
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define umap unordered_map
#define all(x) x.begin(),x.end()
#define mk make_pair
#define pb push_back
#define ckmax(x,y) x=max(x,y)
#define ckmin(x,y) x=min(x,y)
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define per(i,r,l) for(int i=r;i>=l;--i)
using namespace std;
inline int read(){
	int x=0,f=0; char ch=getchar();
	while(!isdigit(ch)) f|=(ch==45),ch=getchar();
	while(isdigit(ch)) x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return f?-x:x;
}
#define N 1005
#define M 12
int n,m,a[N],b[N],nn,sa[1<<M],sb[1<<M],g[N][1<<M],f[N][1<<M],inv[N],C[N][N],fac[N];
const int mo=998244353;
inline void red(int &x){x>=mo?x-=mo:0;}
inline int qpow(int x,int b){
	int res=1;
	for(;b;x=x*x%mo,b>>=1) if(b&1) res=res*x%mo;
	return res;
}
signed main(){
	n=read(),m=read();
	for(int i=0;i<m;++i) a[i]=read(),sa[1<<i]=a[i];
	for(int i=0;i<m;++i) b[i]=read(),nn+=b[i],sb[1<<i]=b[i];
	for(int s=0;s<(1<<m);++s){
		sa[s]=sa[lowbit(s)]+sa[s^lowbit(s)];
		sb[s]=sb[lowbit(s)]+sb[s^lowbit(s)];
	}
	fac[0]=C[0][0]=1;
	for(int i=1;i<=n;++i) inv[i]=qpow(i,mo-2),fac[i]=fac[i-1]*i%mo;
	for(int i=1;i<=n;++i){
		C[i][0]=1;
		for(int j=1;j<=i;++j) red(C[i][j]=C[i-1][j]+C[i-1][j-1]);
	}
	f[0][0]=1;
	for(int i=0;i<nn;++i){
		for(int s=0;s<(1<<m);++s){
			int t=n-i-(sa[s]-sb[s]);
			red(f[i+1][s]+=f[i][s]*inv[t]%mo);
			red(g[i+1][s]+=g[i][s]*inv[t]%mo);
			red(g[i+1][s]+=(n-i)*inv[t]%mo*inv[t]%mo*f[i][s]%mo);
			for(int j=0;j<m;++j){
				if((1<<j)&s) continue;
				int tmp=inv[t]*C[i-sb[s]][b[j]-1]%mo*C[a[j]][b[j]]%mo*fac[b[j]]%mo;
				red(f[i+1][s|(1<<j)]+=f[i][s]*tmp%mo);
				red(g[i+1][s|(1<<j)]+=g[i][s]*tmp%mo);
				red(g[i+1][s|(1<<j)]+=(n-i)*inv[t]%mo*tmp%mo*f[i][s]%mo);
			}
		}
	}
	cout<<g[nn][(1<<m)-1];
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5724kb

input:

2 2
1 1
1 1

output:

2

result:

ok answer is '2'

Test #2:

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

input:

4 2
2 2
2 1

output:

582309210

result:

ok answer is '582309210'

Test #3:

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

input:

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

output:

0

result:

wrong answer expected '5', found '0'