QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#699825 | #9561. 树数叔术 | Nesraychan | 100 ✓ | 204ms | 4224kb | C++14 | 1.8kb | 2024-11-02 10:52:19 | 2024-11-02 10:52:20 |
Judging History
answer
#include<bits/stdc++.h>
#define IL inline
#define reg register
#define N 155
IL int read()
{
reg int x=0,f=0; reg char ch=getchar();
while(ch<'0'||ch>'9')f|=ch=='-',ch=getchar();
while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
return f?-x:x;
}
int mod;
IL int Add(reg int x,reg int y){return x+y<mod?x+y:x+y-mod;}
IL void Pls(reg int &x,reg int y){x=Add(x,y);}
IL int Mul(reg int x,reg int y){reg long long r=1ll*x*y; return r<mod?r:r%mod;}
int n,m,f[N][N],g[N][N],c[N][N],nf[N][N];
IL int C(reg int n,reg int m)
{
if(n==m)return 1;
if(n<m||m<0)return 0;
return c[n][m];
}
main()
{
n=read(),m=read(),mod=read();
if(m>n)puts("0"),exit(0);
for(reg int i=0;i<=n;++i)c[i][0]=1;
for(reg int i=1,j;i<=n;++i)for(j=1;j<=i;++j)
c[i][j]=Add(c[i-1][j],c[i-1][j-1]);
// for(reg int i=0,j;i<=n;++i)for(j=0;j<=i;++j)
// printf("%d%c",c[i][j]," \n"[j==i]);
f[1][0]=1;
for(reg int x=1,i,j,k,w;x<=m;++x)
{
// printf(">> %d\n",x);
for(i=1;i<=n;++i)for(j=0;i+j<=n;++j)if(w=f[i][j])
{
// printf("f[%d][%d] = %d\n",i,j,w);
// if(x==3&&!j)continue;
// if(x==2)printf("[%d, %d, %d, val1 = %d]\n",i,j,w,Mul(Mul(w,i+j),i+j+1));
for(k=1;k<=j;++k)Pls(g[i+k][j-k],Mul(w,C(j,k)));
Pls(nf[i+1][j],Mul(Mul(w,i+j),i+j+1));
Pls(nf[i+1][j+1],Mul(Mul(w,i+j-1),Mul(i+j+1,i+j+2)));
for(k=1;i+j+k<=n;++k)
w=Mul(w,i+j+k),Pls(nf[i+k][j],Mul(w,C(k+i+j-2,i+j-2)));
}
for(i=1;i<=n;++i)for(j=0;i+j<=n;++j)if(w=g[i][j])for(k=0;i+j+k<=n;++k)
Pls(nf[i+k][j],Mul(w,C(k+i+j-2,i+j-2))),w=Mul(w,i+j+k+1);
for(i=1;i<=n;++i)for(j=0;i+j<=n;++j)
f[i][j]=nf[i][j],nf[i][j]=g[i][j]=0;
}
printf("%d\n",f[n][0]);
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 5
Accepted
Test #1:
score: 5
Accepted
time: 0ms
memory: 3928kb
input:
1 1 624295285
output:
0
result:
ok single line: '0'
Test #2:
score: 5
Accepted
time: 0ms
memory: 3684kb
input:
4 684813415 564954712
output:
0
result:
ok single line: '0'
Test #3:
score: 5
Accepted
time: 0ms
memory: 3884kb
input:
4 2 844826878
output:
24
result:
ok single line: '24'
Test #4:
score: 5
Accepted
time: 0ms
memory: 3660kb
input:
4 17724073 252218682
output:
0
result:
ok single line: '0'
Test #5:
score: 5
Accepted
time: 0ms
memory: 3996kb
input:
4 3 697681963
output:
384
result:
ok single line: '384'
Subtask #2:
score: 15
Accepted
Test #6:
score: 15
Accepted
time: 0ms
memory: 3940kb
input:
6 4 956647977
output:
238320
result:
ok single line: '238320'
Test #7:
score: 15
Accepted
time: 0ms
memory: 3536kb
input:
6 450615260 491361886
output:
0
result:
ok single line: '0'
Test #8:
score: 15
Accepted
time: 0ms
memory: 3932kb
input:
6 5 339344353
output:
933120
result:
ok single line: '933120'
Test #9:
score: 15
Accepted
time: 0ms
memory: 3928kb
input:
6 3 842228619
output:
23760
result:
ok single line: '23760'
Test #10:
score: 15
Accepted
time: 0ms
memory: 3880kb
input:
6 5 331699652
output:
933120
result:
ok single line: '933120'
Subtask #3:
score: 30
Accepted
Test #11:
score: 30
Accepted
time: 2ms
memory: 3976kb
input:
48 26 424594716
output:
362283012
result:
ok single line: '362283012'
Test #12:
score: 30
Accepted
time: 0ms
memory: 3544kb
input:
49 1000000000 738885247
output:
0
result:
ok single line: '0'
Test #13:
score: 30
Accepted
time: 2ms
memory: 3932kb
input:
48 39 688951620
output:
598399200
result:
ok single line: '598399200'
Test #14:
score: 30
Accepted
time: 0ms
memory: 3592kb
input:
50 476039414 292870080
output:
0
result:
ok single line: '0'
Test #15:
score: 30
Accepted
time: 3ms
memory: 3984kb
input:
50 48 245196368
output:
123576912
result:
ok single line: '123576912'
Subtask #4:
score: 50
Accepted
Test #16:
score: 50
Accepted
time: 0ms
memory: 3592kb
input:
150 526250070 197316869
output:
0
result:
ok single line: '0'
Test #17:
score: 50
Accepted
time: 196ms
memory: 4224kb
input:
149 116 671784452
output:
18945228
result:
ok single line: '18945228'
Test #18:
score: 50
Accepted
time: 187ms
memory: 4168kb
input:
146 144 906402626
output:
438777234
result:
ok single line: '438777234'
Test #19:
score: 50
Accepted
time: 188ms
memory: 4220kb
input:
147 143 705666477
output:
70408701
result:
ok single line: '70408701'
Test #20:
score: 50
Accepted
time: 204ms
memory: 4164kb
input:
150 147 453481175
output:
336290325
result:
ok single line: '336290325'