QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#388944 | #6349. Is This FFT? | zhouhuanyi | WA | 0ms | 12572kb | C++14 | 2.6kb | 2024-04-13 21:55:39 | 2024-04-13 21:55:39 |
Judging History
answer
#include<iostream>
#include<cstdio>
#define N 802
using namespace std;
int read()
{
char c=0;
int sum=0;
while (c<'0'||c>'9') c=getchar();
while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
return sum;
}
int n,F[N+1],pw[N+1][N+1],dp[N+1][N+1],DP[N+1][N+1],sdp[N+1][N+1],sDP[N+1][N+1],delta[N+1],sdelta[N+1][N+1],mod,fac[N+1],invfac[N+1],inv[N+1],C[N+1][N+1];
unsigned long long d;
int fast_pow(int a,int b)
{
int res=1,mul=a;
while (b)
{
if (b&1) res=1ll*res*mul%mod;
mul=1ll*mul*mul%mod,b>>=1;
}
return res;
}
void Adder(int &x,int d)
{
x+=d;
if (x>=mod) x-=mod;
return;
}
void Adder2(int &x,int d)
{
x+=d;
if (x<0) x+=mod;
return;
}
int MD(int x)
{
return x>=mod?x-mod:x;
}
int MD2(int x)
{
return x<0?x+mod:x;
}
int get_mod(long long x)
{
int r=x-(((__int128)(x)*d)>>64)*mod;
return r>=mod?r-mod:r;
}
void laguange(int x)
{
for (int i=1;i<=n+1;++i)
for (int j=0;j<=F[x];++j)
Adder(DP[x][j],get_mod(1ll*sDP[x][i]*sdelta[i][j]));
return;
}
void get(int x)
{
for (int i=1;i<=n+1;++i)
for (int j=0;j<=F[x];++j)
Adder(sdp[x][i],get_mod(1ll*dp[x][j]*pw[i][j]));
return;
}
int main()
{
n=read(),mod=read(),d=-1ull/mod,fac[0]=1;
for (int i=1;i<=N;++i) fac[i]=1ll*fac[i-1]*i%mod;
invfac[N]=fast_pow(fac[N],mod-2);
for (int i=N-1;i>=0;--i) invfac[i]=1ll*invfac[i+1]*(i+1)%mod;
for (int i=1;i<=N;++i) inv[i]=1ll*fac[i-1]*invfac[i]%mod;
for (int i=0;i<=N;++i)
for (int j=0;j<=i;++j)
C[i][j]=1ll*fac[i]*invfac[j]%mod*invfac[i-j]%mod;
for (int i=1;i<=n+1;++i)
{
pw[i][0]=1;
for (int j=1;j<=n;++j) pw[i][j]=1ll*pw[i][j-1]*i%mod;
}
for (int i=1;i<=n+1;++i) sDP[0][i]=1;
delta[0]=1;
for (int i=1;i<=n+1;++i)
{
for (int j=n;j>=1;--j) delta[j]=MD2(delta[j-1]-1ll*i*delta[j]%mod);
delta[0]=MD2(-1ll*i*delta[0]%mod);
}
for (int i=1;i<=n+1;++i)
{
delta[0]=MD2(-1ll*inv[i]*delta[0]%mod);
for (int j=1;j<=n;++j) delta[j]=1ll*inv[i]*MD2(delta[j-1]-delta[j])%mod;
for (int j=0;j<=n;++j)
{
if (!((n+1-i)&1)) sdelta[i][j]=1ll*delta[j]*invfac[i-1]%mod*invfac[n+1-i]%mod;
else sdelta[i][j]=MD2(-1ll*delta[j]*invfac[i-1]%mod*invfac[n+1-i]%mod);
}
for (int j=n;j>=1;--j) delta[j]=MD2(delta[j-1]-1ll*i*delta[j]%mod);
delta[0]=MD2(-1ll*i*delta[0]%mod);
}
for (int i=0;i<=n;++i) F[i]=min(i,n-i+1);
for (int i=1;i<=n;++i)
{
laguange(i-1);
for (int j=0;j<=F[i];++j) Adder(dp[i][max(j-1,1)],DP[i-1][j]);
get(i);
for (int j=1;j<=i;++j)
for (int k=1;k<=n+1;++k)
Adder(sDP[i][k],get_mod(1ll*get_mod(1ll*sDP[i-j][k]*sdp[j][k])*C[i-1][j-1]));
}
printf("%d\n",DP[n-1][1]);
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 12572kb
input:
10 998244353
output:
11033
result:
wrong answer 1st numbers differ - expected: '1', found: '11033'