QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#722298#7754. Rolling For DaysxzzduangRE 1ms5796kbC++232.1kb2024-11-07 18:31:522024-11-07 18:31:52

Judging History

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

  • [2024-11-07 18:31:52]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:5796kb
  • [2024-11-07 18:31:52]
  • 提交

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();
	int fick=0;
	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(),fick|=(b[i]==0)*(1<<i),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][fick]=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: 5640kb

input:

2 2
1 1
1 1

output:

2

result:

ok answer is '2'

Test #2:

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

input:

4 2
2 2
2 1

output:

582309210

result:

ok answer is '582309210'

Test #3:

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

input:

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

output:

5

result:

ok answer is '5'

Test #4:

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

input:

4 4
1 1 1 1
1 1 1 0

output:

831870299

result:

ok answer is '831870299'

Test #5:

score: 0
Accepted
time: 1ms
memory: 5740kb

input:

5 2
4 1
2 1

output:

598946616

result:

ok answer is '598946616'

Test #6:

score: 0
Accepted
time: 1ms
memory: 5796kb

input:

5 2
3 2
3 1

output:

482484776

result:

ok answer is '482484776'

Test #7:

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

input:

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

output:

665496242

result:

ok answer is '665496242'

Test #8:

score: 0
Accepted
time: 1ms
memory: 5776kb

input:

3 3
1 1 1
1 1 0

output:

499122180

result:

ok answer is '499122180'

Test #9:

score: -100
Runtime Error

input:

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

output:


result: