QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#838462 | #9561. 树数叔术 | eastcloud | 0 | 0ms | 3656kb | C++23 | 2.7kb | 2024-12-31 11:48:55 | 2024-12-31 11:48:56 |
answer
#include<bits/stdc++.h>
#define ll long long
#define pi pair<int,int>
#define vi vector<int>
#define cpy(x,y,s) memcpy(x,y,sizeof(x[0])*(s))
#define mset(x,v,s) memset(x,v,sizeof(x[0])*(s))
#define all(x) begin(x),end(x)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ary array
#define eb emplace_back
#define IL inline
#define For(i,j,k) for(int i=(j);i<=(k);i++)
#define Fol(i,k,j) for(int i=(k);i>=(j);i--)
using namespace std;
#define N 52
int read(){
int x=0,f=1;char ch=getchar();
while(ch<'0' || ch>'9')f=(ch=='-'?-1:f),ch=getchar();
while(ch>='0' && ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
return x*f;
}
void write(int x){
if(x<0)x=-x,putchar('-');
if(x/10)write(x/10);
putchar(x%10+'0');
}
void debug(auto &&...x){
((cerr<<x<<' '),...);
cerr<<'\n';
}
int mod;
IL int pls(int x,int y){return (x+y>=mod?x+y-mod:x+y);}
IL int sub(int x,int y){return (x-y<0?x-y+mod:x-y);}
IL void Add(int &x,int y){x=pls(x,y);}
IL void Dec(int &x,int y){x=sub(x,y);}
IL int mul(int x,int y){return x*1ll*y%mod;}
IL int qp(int x,int y=mod-2){int ans=1;while(y){if(y&1)ans=mul(ans,x);x=mul(x,x);y>>=1;}return ans;}
int fac[N],ifac[N],inv[N];
IL int C(int x,int y){return mul(fac[x],mul(ifac[y],ifac[x-y]));}
IL void init(){
fac[0]=ifac[0]=inv[0]=inv[1]=1;
for(int i=1;i<N;i++)fac[i]=mul(fac[i-1],i);
ifac[N-1]=qp(fac[N-1]);
for(int i=N-2;i>=1;i--)ifac[i]=mul(ifac[i+1],i+1);
for(int i=2;i<N;i++)inv[i]=mul((mod-mod/i),inv[mod%i]);
}
int f[2][N][N];//虚树大小和空点数量
int g[2][N][N];
int main(){
#ifdef EAST_CLOUD
freopen("a.in","r",stdin);
//freopen("a.out","w",stdout);
#endif
int n=read(),V=read();mod=read();init();
if(V>=n){write(0);return 0;}
f[0][1][0]=1;
For(i,0,V-1){
int cur=(i&1),nex=((i&1)^1);
For(j,0,n)For(k,0,j){
if(!f[cur][j][k])continue;
//debug(i,j,k,f[cur][j][k]);
if(j+1<=n)Add(f[nex][j+1][k],mul(f[cur][j][k],j));
if(j+2<=n)Add(f[nex][j+2][k+1],mul(f[cur][j][k],j-1));
For(l,0,k)Add(g[(l?1:0)][j][k-l],mul(C(k,l),f[cur][j][k]));
f[cur][j][k]=0;
}
For(op,0,1)For(j,0,n)For(k,j,n){
if(!g[op][j][k])continue;
if(j==1){
if(op)Add(f[nex][j][k],g[op][j][k]);
g[op][j][k]=0;continue;
}
For(l,(op?0:1),n){
if(j+l<=n)Add(f[nex][j+l][k],mul(g[op][j][k],C(l+j-2,j-2)));
else break;
}
g[op][j][k]=0;
}
}
write(mul(f[(V)&1][n][0],fac[n]));
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 5
Accepted
time: 0ms
memory: 3644kb
input:
1 1 624295285
output:
0
result:
ok single line: '0'
Test #2:
score: 5
Accepted
time: 0ms
memory: 3544kb
input:
4 684813415 564954712
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Wrong Answer
time: 0ms
memory: 3640kb
input:
4 2 844826878
output:
0
result:
wrong answer 1st lines differ - expected: '24', found: '0'
Subtask #2:
score: 0
Wrong Answer
Test #6:
score: 0
Wrong Answer
time: 0ms
memory: 3496kb
input:
6 4 956647977
output:
0
result:
wrong answer 1st lines differ - expected: '238320', found: '0'
Subtask #3:
score: 0
Wrong Answer
Test #11:
score: 0
Wrong Answer
time: 0ms
memory: 3656kb
input:
48 26 424594716
output:
0
result:
wrong answer 1st lines differ - expected: '362283012', found: '0'
Subtask #4:
score: 0
Runtime Error
Test #16:
score: 50
Accepted
time: 0ms
memory: 3608kb
input:
150 526250070 197316869
output:
0
result:
ok single line: '0'
Test #17:
score: 0
Runtime Error
input:
149 116 671784452