QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#288835#6325. Peaceful Results11d10xyTL 1ms5612kbC++142.6kb2023-12-23 13:47:432023-12-23 13:47:44

Judging History

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

  • [2023-12-23 13:47:44]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:5612kb
  • [2023-12-23 13:47:43]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using i64=long long;
using poly=vector<i64>;
constexpr i64 mod=998244353,i3=(mod+1)/3;
auto qpow=[](i64 p,i64 t){i64 r=1;for(;t;t>>=1,p=p*p%mod)if(t&1)(r*=p)%=mod;return r;};
auto pls=[](i64 x,i64 y){return x+y>=mod?x+y-mod:x+y;};
auto mns=[](i64 x,i64 y){return x-y<0?x-y+mod:x-y;};
i64 rp[1500010],fac[1500010],ifac[1500010],ans;
void init(int n){
    rp[n]=1,rp[n|1]=qpow(3,(mod-1)/n);
    for(int i=2;i<n;i++)rp[n|i]=rp[n|i-1]*rp[n|1]%mod;
    for(int i=n-1;i;i--)rp[i]=rp[i<<1];
}
void ntt(poly&f,int n,int inv){
    f.resize(n);i64*a=f.data();
    for(int i=1,r=0;i<n;i++)
    if((r^=n-(n>>__builtin_ffs(i)))>i)swap(a[i],a[r]);
    for(int hf=1;hf<n;hf<<=1)
    for(i64*i=a;i!=a+n;i+=hf*2)
    for(i64*j=i,x,y,*p=rp+hf*2;j!=i+hf;j++,p++)
    x=*j,y=*(j+hf)**p%mod,*j=pls(x,y),*(j+hf)=mns(x,y);
    if(inv==-1){i64 i=qpow(n,mod-2);for(i64&x:f)(x*=i)%=mod;reverse(a+1,a+n);}
}
int main(){
    int n,a[10];
    cin>>n;
    fac[0]=1;for(int i=1;i<=n;i++)fac[i]=fac[i-1]*i%mod;
    ifac[n]=qpow(fac[n],mod-2);for(int i=n;i;i--)ifac[i-1]=ifac[i]*i%mod;
    for(int i=1;i<=9;i++)cin>>a[i];
    i64 w2=a[2]*2+a[3]+a[5]*2+a[6]-3*a[7]-a[8]-2*a[9],
    w3=a[2]+2*a[3]+a[5]+2*a[6]-3*a[7]-2*a[8]-a[9],
    w5=2*a[2]+a[3]-a[5]+a[6]-a[8]-2*a[9],
    w6=a[2]+2*a[3]-2*a[5]-a[6]+a[8]-a[9],
    w7=-3*a[2]-3*a[3]+3*a[7]+3*a[8]+3*a[9],
    w8=-2*a[2]-a[3]+a[5]-a[6]+3*a[7]+a[8]+2*a[9],
    w9=-a[2]-2*a[3]-a[5]-2*a[6]+3*a[7]+2*a[8]+4*a[9];
    if(w2%3||w3%3||w5%3||w6%3||w7%3||w8%3||w9%3)return cout<<0,0;
    w2/=3,w3/=3,w5/=3,w6/=3,w7/=3,w8/=3,w9/=3;
    for(int x1=0;x1<=n;x1++)
    for(int x4=0;x4<=n;x4++){
        int x2=x1+w2,x3=x1+w3,x5=x4+w5,x6=x4+w6,x7=w7-x1-x4,x8=w8-x1-x4,x9=w9-x1-x4;
        if(x1>=0&&x2>=0&&x3>=0&&x4>=0&&x5>=0&&x6>=0&&x7>=0&&x8>=0&&x9>=0){
            (ans+=ifac[x1]*ifac[x2]%mod*ifac[x3]%mod*ifac[x4]%mod*ifac[x5]%mod*ifac[x6]%mod*ifac[x7]%mod*ifac[x8]%mod*ifac[x9])%=mod;
        }
    }
    // int N=1<<__lg(n)+1;init(N);
    // poly f(n+1),g(n+1);
    // for(int i=0;i<=n;i++){
    //     int a=i+w2,b=i+w3,c=i+w5,d=i+w6;
    //     if(a>=0&&b>=0&&a<=n&&b<=n)f[i]=ifac[i]*ifac[a]%mod*ifac[b]%mod;
    //     if(c>=0&&d>=0&&c<=n&&d<=n)g[i]=ifac[i]*ifac[c]%mod*ifac[d]%mod;
    // }ntt(f,N,1),ntt(g,N,1);
    // for(int i=0;i<N;i++)(f[i]*=g[i])%=mod;
    // ntt(f,N,-1);
    // for(int s1=0;s1<=n;s1++){
    //     int a=w7-s1,b=w8-s1,c=w9-s1;
    //     if(a<0||b<0||c<0||a>n||b>n||c>n)continue;
    //     (ans+=f[s1]*ifac[a]%mod*ifac[b]%mod*ifac[c])%=mod;
    // }
    cout<<ans*fac[n]%mod;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5612kb

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: 1ms
memory: 5612kb

input:

3
0 1 2
3 0 0
1 1 1

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: -100
Time Limit Exceeded

input:

333333
111111 111111 111111
111111 111111 111111
111111 111111 111111

output:


result: