QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#426498#6325. Peaceful Resultsby_chanceWA 17ms25708kbC++172.5kb2024-05-31 13:01:132024-05-31 13:01:14

Judging History

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

  • [2024-05-31 13:01:14]
  • 评测
  • 测评结果:WA
  • 用时:17ms
  • 内存:25708kb
  • [2024-05-31 13:01:13]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=1.05e6+5,P=998244353;
inline void pls(int&a,int b){a+=b;if(a>=P)a-=P;}
int qpow(int a,int b=P-2){
    int c=1;
    for(;b;b>>=1,a=1ll*a*a%P)
        if(b&1)c=1ll*c*a%P;
    return c;
}
int sid,T,n,fac[N],ifac[N],inv[N];
int a[15],b[15],flag;
int f[N],g[N],h[N],rev[N],_G[N],invG[N];
int ask(int i){if(i>=0&&i<N)return ifac[i];else return 0;}
void NTT(int*f,int n,int op){
    for(int i=0;i<n;++i)if(i<rev[i])swap(f[i],f[rev[i]]);
    for(int p=2;p<=n;p<<=1){
        int len=p>>1,tG=(op==1?_G[p]:invG[p]);
        for(int k=0;k<n;k+=p){
            int buf=1;
            for(int l=k;l<k+len;++l){
                int tmp=1ll*f[l+len]*buf%P;f[l+len]=f[l];
                pls(f[l+len],P-tmp);pls(f[l],tmp);buf=1ll*buf*tG%P;
            }
        }
    }
    if(op==-1){
        for(int i=0;i<n;++i)
            f[i]=1ll*f[i]*inv[n]%P;
    }
}
void times(int*f,int*g,int m){
    int n=1;for(;n<=2*m;n<<=1);for(int i=m;i<n;++i)f[i]=g[i]=0;
    for(int i=0;i<n;++i)rev[i]=(rev[i>>1]>>1)|((i&1)?(n>>1):0);
    NTT(f,n,1);NTT(g,n,1);for(int i=0;i<n;++i)f[i]=1ll*f[i]*g[i]%P;
    NTT(f,n,-1);for(int i=m;i<n;++i)f[i]=0;
}
void init(){
    fac[0]=ifac[0]=inv[1]=1;
    for(int i=1;i<N;++i)fac[i]=1ll*fac[i-1]*i%P;
    for(int i=2;i<N;++i)inv[i]=1ll*(P-P/i)*inv[P%i]%P;
    for(int i=1;i<N;++i)ifac[i]=1ll*ifac[i-1]*inv[i]%P;
    for(int i=1;i<N;i<<=1)_G[i]=qpow(3,(P-1)/i),invG[i]=qpow((P+1)/3,(P-1)/i);    
}
int main(){
    double st_t=clock()*1000/CLOCKS_PER_SEC;
    scanf("%d%d",&sid,&T);init();
    while(T--){
        scanf("%d",&n);flag=1;
        for(int i=1;i<=9;++i)scanf("%d",a+i);
        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 flag=0;}
        if(!flag){printf("0\n");continue;}
        for(int i=0;i<=n;++i){
            f[i]=1ll*ask(b[1]-n+i)*ask(b[2]-n+i)%P*ask(b[3]-n+i)%P;
            g[i]=1ll*ask(b[4]+i)*ask(b[7]+i)%P*ask(b[9]+i)%P;
            h[i]=1ll*ask(b[5]+i)*ask(b[6]+i)%P*ask(b[8]+i)%P;
        }
        times(f,g,n+1);int ans=0;
        for(int i=0;i<=n;i++)ans=(ans+1ll*f[i]*h[n-i]%P)%P;
        printf("%lld\n",1ll*fac[n]*ans%P);
    }
    fprintf(stderr,"%.2lfms\n",clock()*1000/CLOCKS_PER_SEC-st_t);
    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 17ms
memory: 25708kb

input:

2
2 0 0
1 1 0
1 0 1

output:

0
0

result:

wrong answer 1st numbers differ - expected: '2', found: '0'