QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#101895#6349. Is This FFT?zhouhuanyi#TL 5ms6308kbC++112.1kb2023-05-01 17:26:112023-05-01 17:26:13

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-01 17:26:13]
  • 评测
  • 测评结果:TL
  • 用时:5ms
  • 内存:6308kb
  • [2023-05-01 17:26:11]
  • 提交

answer

#include<iostream>
#include<cstdio>
#define N 250
#define M 62500
using u32 = unsigned int;
using u64 = unsigned long long;
using u128 = __uint128_t;
using namespace std;
struct Barrett {u64 b, m;Barrett() : b(), m() {}Barrett(u64 _b) : b(_b), m(-1ULL / _b) {}u32 reduce(u64 x) {u64 q = (u64)((u128(m) * x) >> 64), r = x - q * b;return r - b * (r >= b);}} BA;
u32 mult(u32 x, u32 y) {return BA.reduce((u64)x * y);}
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,ans,S[N+1],F[M+1],fac[M+1],invfac[M+1],inv[M+1],dp[N+1][M+1],mod;
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 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;
}
int C(int x,int y)
{
    if (x<y) return 0;
    return mult(mult(fac[x],invfac[y]),invfac[x-y]);
}
int main()
{
    n=read(),mod=read(),dp[1][0]=fac[0]=1,BA=Barrett(mod);
    for (int i=1;i<=M;++i) fac[i]=1ll*fac[i-1]*i%mod;
    invfac[M]=fast_pow(fac[M],mod-2);
    for (int i=M-1;i>=0;--i) invfac[i]=1ll*invfac[i+1]*(i+1)%mod;
    for (int i=1;i<=M;++i) inv[i]=1ll*fac[i-1]*invfac[i]%mod;
    for (int i=1;i<=n;++i) S[i]=S[i-1]+i-1;
    for (int i=2;i<=n;++i)
    {
	for (int j=1;j<=i-1;++j)
	{
	    for (int k=i-2;k<=S[j]+S[i-j];++k) F[k]=0;
	    for (int k=j-1;k<=S[j];++k)
		for (int t=i-j-1;t<=S[i-j];++t)
		    Adder(F[k+t],mult(dp[j][k],dp[i-j][t]));
	    for (int k=i-2;k<=S[j]+S[i-j];++k)
		for (int t=0;t<=j*(i-j)-1;++t)
		{
		    if (!(t&1)) Adder(dp[i][k+t+1],mult(F[k],C(j*(i-j)-1,t)));
		    else Adder2(dp[i][k+t+1],-mult(F[k],C(j*(i-j)-1,t)));
		}
	}
	for (int j=i-1;j<=S[i];++j) dp[i][j]=mult(dp[i][j],inv[j]);
    }
    for (int i=2;i<=n;++i)
    {
	ans=0;
	for (int j=i-1;j<=S[i];++j) Adder(ans,dp[i][j]);
	printf("%lld\n",1ll*ans*fac[i]%mod*inv[2]%mod);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 5ms
memory: 6308kb

input:

10 998244353

output:

1
1
532396989
328786831
443364983
567813846
34567523
466373946
474334062

result:

ok 9 numbers

Test #2:

score: -100
Time Limit Exceeded

input:

250 998244353

output:


result: