QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#335530 | #7754. Rolling For Days | lefy | WA | 1ms | 3896kb | C++14 | 2.2kb | 2024-02-23 15:38:40 | 2024-02-23 15:38:41 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e3+10,M=1<<12,mod=998244353;
int a[15],b[15],val[M],vb[M];
int c[N][N];
ll C(int x,int y){
if(x<0||y<0||x<y)return 0;
return c[x][y];
}
ll inv[N],Inv[N],sinv[N];
ll f[N][M],g[N][M],sf[N][M],sg[N][M],sg2[N][M],fac[N],G[N][M];
ll getmul(int l,int r){
if(l>r||r<=0)return 1;
if(!l)return fac[r];
return fac[r]*Inv[l-1]%mod;
}
int main() {
int n,m;
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++)scanf("%d",&a[i]);
int st=0;
for(int i=1;i<=m;i++){
scanf("%d",&b[i]);
if(!b[i])st|=1<<i-1;
}
for(int s=0;s<(1<<m);s++)for(int i=1;i<=m;i++)if(s&(1<<i-1)){
val[s]+=a[i]-b[i],vb[s]+=b[i];
// cout<<i<<"\n";
}
for(int i=0;i<=n;i++){
c[i][0]=1;
for(int j=1;j<=i;j++)c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod;
}
sinv[0]=Inv[0]=Inv[1]=inv[1]=1;
sinv[1]=2;fac[1]=fac[0]=1;
for(int i=2;i<=n;i++){
fac[i]=fac[i-1]*i%mod;
sinv[i]=inv[i]=inv[mod%i]*(mod-mod/i)%mod,Inv[i]=Inv[i-1]*inv[i]%mod;
sinv[i]=(sinv[i]+sinv[i-1])%mod;
}
G[0][st]=sg2[0][st]=sf[0][st]=sg[0][st]=g[0][st]=1;
for(int i=0;i<=vb[(1<<m)-1];i++)for(int s=0;s<(1<<m);s++){
for(int x=1;x<=m;x++)if((s&(1<<x-1))&&b[x]){
ll sum=C(i-1-vb[s-(1<<x-1)],b[x]-1)*getmul(a[x]-b[x]+1,a[x])%mod;
g[i][s]+=sg[i-1][s-(1<<x-1)]*sum%mod;
// if(i==1&&s==2)cout<<g[i][s]<<"\n";
f[i][s]+=sf[i-1][s-(1<<x-1)]*sum%mod;
sum=sum*val[s-(1<<x-1)]%mod*sg2[i-1][s-(1<<x-1)]%mod;
f[i][s]+=sum;
g[i][s]%=mod,f[i][s]%=mod;
}
sg[i][s]=((i?sg[i-1][s]:0)+g[i][s])%mod;
if(i<n)sg[i][s]=sg[i][s]*inv[n+1-i-1-val[s]]%mod;
G[i][s]=((i?G[i-1][s]:0)+g[i][s])%mod;
sg2[i][s]=((i?sg2[i-1][s]:0)+G[i][s]*inv[n+1-val[s]-i+1]%mod)%mod;
sf[i][s]=((i?sf[i-1][s]:0)+f[i][s])%mod;
if(i<n)sf[i][s]=sf[i][s]*inv[n+1-i-1-val[s]]%mod;
cout<<f[i][s]<<" "<<g[i][s]<<"\n";
}
// cout<<f[vb[(1<<m)-1]][(1<<m)-1]<<"\n";
printf("%lld",(f[vb[(1<<m)-1]][(1<<m)-1]+vb[(1<<m)-1])%mod);
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3896kb
input:
2 2 1 1 1 1
output:
0 1 0 0 0 0 0 0 0 0 0 499122177 0 499122177 0 0 0 0 0 499122177 0 499122177 0 1 2
result:
wrong answer expected '2', found '0'