QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#150757 | #6349. Is This FFT? | 275307894a | TL | 1ms | 3768kb | C++14 | 1.5kb | 2023-08-26 08:12:23 | 2023-08-26 08:12:26 |
Judging History
answer
#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;using LL=__int128;
const int N=250+5,M=N*N+5,K=14348907+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const ll INF=1e18+7;mt19937 rnd(time(0));
int n,p,k;ll f[N][M],g[M],frc[N],inv[N];
ll C(int x,int y){return frc[x]*inv[y]%p*inv[x-y]%p;}
void Solve(){
int i,j,h;scanf("%d%d",&n,&p);k=max(n,n*(n-1)/2);
inv[1]=1;for(i=2;i<=k;i++) inv[i]=(p-inv[p%i])*(p/i)%p;
for(frc[0]=inv[0]=i=1;i<=k;i++) frc[i]=frc[i-1]*i%p,inv[i]=inv[i-1]*inv[i]%p;
f[1][0]=1;
for(i=2;i<=n;i++){
int l=i*(i-1)/2;
for(j=1;j<i;j++){
fill(g+1,g+l+1,0);
int l1=j*(j-1)/2,l2=(i-j)*(i-j-1)/2;
for(int x=0;x<=l1;x++){
for(int y=0;y<=l2;y++) g[x+y+1]+=f[j][x]*f[i-j][y]%p*C(x+y,x)%p*C(l-j*(i-j)-x-y,l1-x)%p;
}
for(h=0;h<=l;h++) f[i][h]=(f[i][h]+g[h]%p*frc[j*(i-j)-1]%p*C(l-h,j*(i-j)-1))%p;
}
for(j=1;j<=l;j++) f[i][j]=(f[i][j]+f[i][j-1])%p;
}
for(i=2;i<=n;i++) printf("%lld\n",f[i][i*(i-1)/2]*inv[i*(i-1)/2]%p*(i^1?frc[i]*(p+1)/2%p:1)%p);
}
int main(){
int t;
// scanf("%d",&t);
t=1;
while(t--) Solve();
cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3768kb
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