QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#746398 | #9125. Majority and Permutation | DaiRuiChen007 | WA | 16ms | 26476kb | C++17 | 2.0kb | 2024-11-14 14:29:54 | 2024-11-14 14:29:55 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
namespace P {
const int MOD=998244353,N=1<<19,G=3;
int rev[N],inv[N],fac[N],ifac[N],w[N<<1];
int ksm(int a,int b=MOD-2) {
int ret=1;
for(;b;a=1ll*a*a%MOD,b=b>>1) if(b&1) ret=1ll*ret*a%MOD;
return ret;
}
void poly_init() {
inv[1]=1;
for(int i=2;i<N;++i) inv[i]=1ll*(MOD-MOD/i)*inv[MOD%i]%MOD;
fac[0]=ifac[0]=1;
for(int i=1;i<N;++i) fac[i]=1ll*fac[i-1]*i%MOD,ifac[i]=1ll*ifac[i-1]*inv[i]%MOD;
for(int k=1;k<=N;k<<=1) {
int x=ksm(G,(MOD-1)/k); w[k]=1;
for(int i=1;i<k;++i) w[i+k]=1ll*x*w[i+k-1]%MOD;
}
}
int plen(int x) { int y=1; for(;y<x;y<<=1); return y; }
void ntt(int *f,bool idft,int n) {
for(int i=0;i<n;++i) {
rev[i]=(rev[i>>1]>>1);
if(i&1) rev[i]|=n>>1;
}
for(int i=0;i<n;++i) if(rev[i]<i) swap(f[i],f[rev[i]]);
for(int k=2,x,y;k<=n;k<<=1) {
for(int i=0;i<n;i+=k) {
for(int j=i;j<i+k/2;++j) {
x=f[j],y=1ll*f[j+k/2]*w[k+j-i]%MOD;
f[j]=(x+y>=MOD)?x+y-MOD:x+y,f[j+k/2]=(x>=y)?x-y:x+MOD-y;
}
}
}
if(idft) {
reverse(f+1,f+n);
for(int i=0,x=ksm(n);i<n;++i) f[i]=1ll*f[i]*x%MOD;
}
}
void poly_mul(const int *f,const int *g,int *h,int n,int m) {
static int a[N],b[N];
for(int i=0;i<n;++i) a[i]=f[i];
for(int i=0;i<m;++i) b[i]=g[i];
int len=plen(n+m-1);
ntt(a,0,len),ntt(b,0,len);
for(int i=0;i<len;++i) h[i]=1ll*a[i]*b[i]%MOD;
ntt(h,1,len);
memset(a,0,sizeof(int)*len);
memset(b,0,sizeof(int)*len);
}
}
const int N=1<<19,MOD=998244353;
int n,m,dp[N],A[N],B[N],C[N];
bool e[N];
void cdq(int l,int r) {
if(l==r) return ;
int mid=(l+r)>>1;
cdq(l,mid);
for(int i=l;i<=mid;++i) A[i-l]=dp[i];
for(int i=0;i<=r-l;++i) B[i]=P::fac[i];
P::poly_mul(A,B,C,mid-l+1,r-l+1);
for(int i=mid+1;i<=r;++i) if(e[i]) dp[i]=(dp[i]+MOD-C[i-l])%MOD;
cdq(mid+1,r);
}
signed main() {
P::poly_init();
scanf("%d%d",&n,&m),n*=2,e[n]=true;
for(int i=1,x;i<=m;++i) scanf("%d",&x),e[x]=true;
dp[0]=1,cdq(0,n);
printf("%d\n",(MOD-dp[n])%MOD);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 12ms
memory: 26436kb
input:
2 2 1 3
output:
14
result:
ok "14"
Test #2:
score: 0
Accepted
time: 16ms
memory: 26368kb
input:
5 4 1 3 7 9
output:
2909184
result:
ok "2909184"
Test #3:
score: 0
Accepted
time: 11ms
memory: 26476kb
input:
5 1 5
output:
3614400
result:
ok "3614400"
Test #4:
score: 0
Accepted
time: 7ms
memory: 26300kb
input:
3 1 3
output:
684
result:
ok "684"
Test #5:
score: -100
Wrong Answer
time: 12ms
memory: 26396kb
input:
5 2 5 9
output:
3254400
result:
wrong answer 1st words differ - expected: '3614400', found: '3254400'