QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#210092#6325. Peaceful Resultsucup-team870RE 365ms57260kbC++173.3kb2023-10-11 01:12:372023-10-11 01:12:37

Judging History

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

  • [2023-10-11 01:12:37]
  • 评测
  • 测评结果:RE
  • 用时:365ms
  • 内存:57260kb
  • [2023-10-11 01:12:37]
  • 提交

answer

// 0.333333 -0.333333 -0.666667 -0.333333 -0.666667 -0.333333 1 -1 -1
// 0 0 0 0 -1 -1 1 -1 -1
// -0.333333 0.333333 -0.333333 -0.666667 0.666667 0.333333 -0 1 -0 
// -0.666667 -0.333333 0.333333 -0.333333 0.333333 0.666667 0 1 0
// -0.333333 -0.666667 -0.333333 0.333333 -0.333333 -0.666667 1 -1 -1
// 0.666667 0.333333 0.666667 0.333333 0.666667 0.333333 -1 -0 1
// 0.333333 0.666667 0.333333 0.666667 0.333333 0.666667 -1 -0 1
#include<bits/stdc++.h>
using namespace std;
#define IOS {cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);}
#define rep(i,j,k) for(int i=j;i<=k;++i)
#define per(i,j,k) for(int i=j;i>=k;--i)
#define P pair<int,int>
#define ll long long
#define vi vector<int>
int K[7][7]={{1,-1,-2,-1,-2,-1,3},{0,0,0,0,-3,-3,3},{-1,1,-1,-2,2,1,0},{-2,-1,1,-1,1,2,0},
{-1,-2,-1,1,-1,-2,3},{2,1,2,1,2,1,-3},{1,2,1,2,1,2,-3} };
int p[7]={-1,-1,0,0,-1,1,1};
const int N=2e6+6,mod=998244353;
ll qp(ll x,ll y){
    ll res=1;
    while(y){
        if(y&1)res=res*x%mod;
        x=x*x%mod; y>>=1;
    } return res;
}
#define poly vi
const int G=3,Gi=qp(G,mod-2);
int limit=1,L=0; int r[N*4];
void NTT(poly& A,int type){
    A.resize(limit);
    for(int i=0;i<limit;++i)if(i<r[i])swap(A[i],A[r[i]]);
    for(int mid=1;mid<limit;mid<<=1){
        ll wn=qp(type==1 ? G:Gi, (mod-1)/(mid<<1));
        for(int j=0;j<limit;j+=(mid<<1)){
            ll w=1;
            for(int k=0;k<mid;k++,w=(w*wn)%mod){
                int x=A[j+k],y=w*A[j+k+mid]%mod;
                A[j+k]=(x+y)%mod, A[j+k+mid]=(x-y+mod)%mod;
            }
        }
    }
}
void poly_mul_init(poly&a, poly&b){
    limit=1; L=0;
    int N=a.size()-1,M=b.size()-1;
    while(limit<=N+M)limit<<=1,++L;
    for(int i=0;i<limit;i++)r[i]=(r[i>>1]>>1|((i&1)<<(L-1)));
}
poly poly_mul(poly a,poly b){
    int n=a.size()+b.size()-1;
    poly_mul_init(a,b);
    NTT(a,1); NTT(b,1);
    rep(i,0,limit-1)a[i]=1ll*a[i]*b[i]%mod;
    NTT(a,-1);
    ll INV=qp(limit,mod-2);
    rep(i,0,limit-1)a[i]=a[i]*INV%mod;
    a.resize(n); return a;
}

ll fac[N],inv[N];
void add(ll &x,ll y){x=(x+y)%mod;}
void dif(ll &x,ll y){x=(x-y+mod)%mod;}
signed main(){
    const int M=2e6;
    fac[0]=1; rep(i,1,M)fac[i]=i*fac[i-1]%mod;
    inv[M]=qp(fac[M],mod-2); per(i,M,1)inv[i-1]=inv[i]*i%mod;
    int _,n; cin>>n;
    int v[8],s[9]={0};
    rep(i,0,2){
        cin>>v[i*2]>>v[i*2+1]>>_;
    }
    v[6]=n;
    rep(i,0,6){
        int sum=0;
        rep(j,0,6)sum+=K[i][j]*v[j];
        if(sum%3){
            cout<<0; return 0;
        }
        s[i]=sum/3;
    }
    auto wk=[&](int v1,int v2,int v3){
        // cout<<v1<<' '<<v2<<' '<<v3<<'\n';
        int l=max({-v1,-v2,-v3}),r=n+min({-v1,-v2,-v3});
        if(l>r){
            cout<<0; exit(0);
        }
        int len=r-l+1;
        vi f(len);
        rep(i,0,len-1){
            int x=i+l;
            f[i]=inv[v1+x]*inv[v2+x]%mod*inv[v3+x]%mod;
        }
        return make_pair(l,f);
    };
    auto [l1,f1]=wk(s[0],s[1],s[4]);
    auto [l2,f2]=wk(s[2],s[3],0);
    auto [l3,f3]=wk(s[5],s[6],0);
    auto f=poly_mul(poly_mul(f1,f2),f3);
    int ls=l1+l2+l3;
    assert(-ls>=0 && -ls<f.size());
    cout<<fac[n]*f[-ls]%mod;
}
/*
3
1 1 1
1 1 1
1 1 1
18

333333
111111 111111 111111
111111 111111 111111
111111 111111 111111
383902959

2
2 0 0
1 1 0
1 0 1
*/

詳細信息

Test #1:

score: 100
Accepted
time: 16ms
memory: 36676kb

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: 19ms
memory: 36568kb

input:

3
0 1 2
3 0 0
1 1 1

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: 0
Accepted
time: 365ms
memory: 57260kb

input:

333333
111111 111111 111111
111111 111111 111111
111111 111111 111111

output:

383902959

result:

ok 1 number(s): "383902959"

Test #4:

score: -100
Runtime Error

input:

1500000
500000 500000 500000
500000 500000 500000
500000 500000 500000

output:


result: