NC225765. Cells
描述
输入描述
The first line contains one integer n (), where n is the number of trucks.
The second line contains n integers (, ), which are the trucks' initial positions.
输出描述
Print the number of ways modulo 998244353 on the only line of output.
示例1
输入:
3 1 2 3
输出:
4
C++ 解法, 执行用时: 869ms, 内存消耗: 53624K, 提交时间: 2021-09-14 20:48:14
#include <bits/stdc++.h> using namespace std; typedef long long LL; const int N=1e7+10,M=998244353,p=1e6; LL R[N],A[N],B[N],n,c[N/10],m,l; LL qmi(LL a,LL b) { LL res=1; while(b) { if(b&1)res=res*a%M; a=a*a%M; b>>=1; } return res%M; } void NTT(LL *A,int f) { for(int i=0;i<m;i++)if(i<R[i])swap(A[i],A[R[i]]); for(int h=2;h<=m;h<<=1) { int wn=qmi(3,(M-1)/h); if(f==-1)wn=qmi(wn,M-2); for(int j=0;j<m;j+=h) { int wk=1; for(int k=j;k<j+h/2;k++) { int x=A[k],y=(LL)wk*A[k+h/2]%M; A[k]=(x+y)%M; A[k+h/2]=(x-y+M)%M; wk=(LL)wk*wn%M; } } } if(f==-1) { int inv=qmi(m,M-2); for(int i=0;i<m;i++)A[i]=(LL)A[i]*inv%M; } } int main() { ios::sync_with_stdio(false); cin.tie(0); cin>>n; LL ans=1,fac=1; for(int i=1;i<=n;i++) { cin>>c[i]; A[c[i]]=1; B[p-c[i]]=1; fac=fac*i%M; ans=ans*qmi(fac,M-2)%M*(c[i]+1)%M; } l=-1; for(m=1;m<=p*2;m<<=1)l++; for(int i=0;i<m;i++)R[i]=(R[i>>1]>>1)|((i&1)<<l); NTT(A,1);NTT(B,1); for(int i=0;i<m;i++)A[i]=A[i]*B[i]%M; NTT(A,-1); for(int i=p+1;i<m;i++)if(A[i])ans=ans*qmi(i-p,A[i])%M; cout<<ans<<"\n"; return 0; }