QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#426710#6325. Peaceful Resultsyingxue_catWA 303ms120624kbC++142.4kb2024-05-31 17:38:102024-05-31 17:38:11

Judging History

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

  • [2024-05-31 17:38:11]
  • 评测
  • 测评结果:WA
  • 用时:303ms
  • 内存:120624kb
  • [2024-05-31 17:38:10]
  • 提交

answer

#include<bits/stdc++.h>
#define il inline
using namespace std;
il int read()
{
    int xr=0,F=1; char cr;
    while(cr=getchar(),cr<'0'||cr>'9') if(cr=='-') F=-1;
    while(cr>='0'&&cr<='9') 
        xr=(xr<<3)+(xr<<1)+(cr^48),cr=getchar();
    return xr*F;
}
#define int long long
const int N=5e6+5,mod=998244353;
int limit,to[N];
il int qpow(int n,int k=mod-2)
{
    int res=1;
    for(;k;n=n*n%mod,k>>=1) if(k&1) res=res*n%mod;
    return res;
}
il void NTT(int *a,int tp)
{
    for(int i=0;i<limit;i++) if(i<to[i]) swap(a[i],a[to[i]]);
    for(int len=1;len<limit;len<<=1)
    {
        int Wn=qpow(qpow(3,(mod-1)/(len<<1)),tp);
        for(int i=0;i<limit;i+=(len<<1))
            for(int j=0,w=1;j<len;j++,w=w*Wn%mod)
            {
                int x=a[i+j],y=a[i+len+j];
                a[i+j]=(x+w*y)%mod,a[i+len+j]=(x-w*y%mod+mod)%mod;
            }
    }
}
il void conv(int *c,int *a,int *b,int n,int m)
{
    limit=1;
    int k=0; while(limit<=n+m) limit<<=1,k++;
    for(int i=0;i<limit;i++) to[i]=(to[i>>1]>>1)|(i&1)<<k-1;
    NTT(a,1),NTT(b,1);
    for(int i=0;i<limit;i++) c[i]=a[i]*b[i]%mod;
    NTT(c,mod-2);
    for(int i=0;i<=n+m;i++) c[i]=c[i]*qpow(limit)%mod;
}
int n,a[10],b[10],h[N],g[N],f[N];
int jc[N],inv[N];
il void init(int mx)
{
    jc[0]=inv[0]=1;
    for(int i=1;i<=mx;i++) jc[i]=jc[i-1]*i%mod;
    inv[mx]=qpow(jc[mx]);
    for(int i=mx-1;i;i--) inv[i]=inv[i+1]*(i+1)%mod;
}
il int F(int x) {return x>=0&&x<N?inv[x]:0;}
signed main()
{
    n=read(); init(N-1);
    for(int i=1;i<=9;i++) a[i]=read();
    bool fg=1;
    b[1]=-a[1]-2*a[2]+2*a[4]+a[5]+2*a[7]+a[8];
    b[2]=-2*a[1]-a[2]+a[4]+2*a[5]+a[7]+2*a[8];b[3]=a[3];
    b[4]=2*a[1]+a[2]-a[4]+a[5]-a[7]-2*a[8];
    b[5]=2*a[1]+a[2]-a[4]-2*a[5]-a[7]+a[8];
    b[6]=a[1]+2*a[2]+a[4]-a[5]-2*a[7]-a[8];
    b[7]=a[1]+2*a[2]-2*a[4]-a[5]+a[7]-a[8];
    for(int i:{1,2,4,5,6,7})
        if(b[i]%3==0) b[i]/=3;
        else
        {
            printf("0\n");
            return 0;
        }
    for(int i=0;i<=n;i++)
    {
        f[i]=F(b[1]-n+i)*F(b[2]-n+i)%mod*F(b[3]-n+i)%mod;
        g[i]=F(b[4]+i)*F(b[7]+i)%mod*F(b[9]+i)%mod;
        h[i]=F(b[5]+i)*F(b[6]+i)%mod*F(b[8]+i)%mod;
    }
    conv(h,f,g,n+1,n+1); int ans=0;
    for(int i=0;i<=n;i++) ans=(ans+f[i]*h[n-i]%mod)%mod;
    printf("%lld\n",jc[n]*ans%mod);
    return 0;
}
/*
2
2 0 0 
1 1 0
1 0 1
*/

详细

Test #1:

score: 100
Accepted
time: 43ms
memory: 89880kb

input:

2
2 0 0
1 1 0
1 0 1

output:

2

result:

ok 1 number(s): "2"

Test #2:

score: 0
Accepted
time: 50ms
memory: 84488kb

input:

3
0 1 2
3 0 0
1 1 1

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: -100
Wrong Answer
time: 303ms
memory: 120624kb

input:

333333
111111 111111 111111
111111 111111 111111
111111 111111 111111

output:

265133808

result:

wrong answer 1st numbers differ - expected: '383902959', found: '265133808'