QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#336702#7754. Rolling For DayslefyWA 1ms4028kbC++142.7kb2024-02-24 19:47:082024-02-24 19:47:08

Judging History

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

  • [2024-02-24 19:47:08]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4028kb
  • [2024-02-24 19:47:08]
  • 提交

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;
}
ll getsum(int l,int r){
    if(l>r||r<=0)return 0;
    if(!l)return sinv[r];
    return (sinv[r]-sinv[l-1]+mod)%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]=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;
            // cout<<sg2[i-1][s-(1<<x-1)]<<"\n";
            f[i][s]+=sum;
            g[i][s]%=mod,f[i][s]%=mod;
        }
        if(i==n)continue;
        sg[i][s]=((i?sg[i-1][s]:0)+g[i][s])%mod;
        sg[i][s]=sg[i][s]*inv[n+1-i-1-val[s]]%mod;
        // if(i){
            // G[i][s]=(G[i-1][s]+g[i][s])%mod;
            // if(i<n)G[i][s]=G[i][s]*inv[n+1-i-1,val[s]]%mod;
        
            ll tmp=inv[n-val[s]-i];
            if(i)sg2[i][s]=(sg2[i-1][s]*tmp%mod+sg2[i-1][s]*tmp%mod*tmp%mod)%mod;
            // sg2[i][s]=((i?sg2[i-1][s]:0)+sg[i][s]*inv[]%mod)%mod;
        
        sg2[i][s]=(sg2[i][s]+g[i][s]*tmp%mod*tmp%mod)%mod;
        // sg2[i][s]=((i?sg2[i-1][s]:0)+g[i][s]*inv[n-])
        sf[i][s]=((i?sf[i-1][s]:0)+f[i][s])%mod;
        sf[i][s]=sf[i][s]*inv[n+1-i-1-val[s]]%mod;
        // cout<<i<<" "<<s<<"\n";
        // 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: 100
Accepted
time: 1ms
memory: 4028kb

input:

2 2
1 1
1 1

output:

2

result:

ok answer is '2'

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 3996kb

input:

4 2
2 2
2 1

output:

831870298

result:

wrong answer expected '582309210', found '831870298'