QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#838467#9561. 树数叔术eastcloud100 ✓81ms4068kbC++232.6kb2024-12-31 11:54:032024-12-31 11:54:07

Judging History

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

  • [2024-12-31 11:54:07]
  • 评测
  • 测评结果:100
  • 用时:81ms
  • 内存:4068kb
  • [2024-12-31 11:54:03]
  • 提交

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 152

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];
IL void init(){
    fac[0]=1;
    for(int i=1;i<N;i++)fac[i]=mul(fac[i-1],i);
}

int f[2][N][N];//虚树大小和空点数量
int g[2][N][N],C[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;C[1][0]=C[1][1]=C[0][0]=1;
    For(i,2,N-1){
        C[i][0]=1;
        For(j,1,N-1)C[i][j]=pls(C[i-1][j-1],C[i-1][j]);
    }
    For(i,0,V-1){
        int cur=(i&1),nex=((i&1)^1);
        For(j,0,n)For(k,0,n){
            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,0,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: 5
Accepted

Test #1:

score: 5
Accepted
time: 0ms
memory: 3612kb

input:

1 1 624295285

output:

0

result:

ok single line: '0'

Test #2:

score: 5
Accepted
time: 0ms
memory: 3480kb

input:

4 684813415 564954712

output:

0

result:

ok single line: '0'

Test #3:

score: 5
Accepted
time: 0ms
memory: 3644kb

input:

4 2 844826878

output:

24

result:

ok single line: '24'

Test #4:

score: 5
Accepted
time: 0ms
memory: 3640kb

input:

4 17724073 252218682

output:

0

result:

ok single line: '0'

Test #5:

score: 5
Accepted
time: 1ms
memory: 3660kb

input:

4 3 697681963

output:

384

result:

ok single line: '384'

Subtask #2:

score: 15
Accepted

Test #6:

score: 15
Accepted
time: 0ms
memory: 3652kb

input:

6 4 956647977

output:

238320

result:

ok single line: '238320'

Test #7:

score: 15
Accepted
time: 0ms
memory: 3544kb

input:

6 450615260 491361886

output:

0

result:

ok single line: '0'

Test #8:

score: 15
Accepted
time: 0ms
memory: 3808kb

input:

6 5 339344353

output:

933120

result:

ok single line: '933120'

Test #9:

score: 15
Accepted
time: 0ms
memory: 3788kb

input:

6 3 842228619

output:

23760

result:

ok single line: '23760'

Test #10:

score: 15
Accepted
time: 0ms
memory: 3660kb

input:

6 5 331699652

output:

933120

result:

ok single line: '933120'

Subtask #3:

score: 30
Accepted

Test #11:

score: 30
Accepted
time: 1ms
memory: 3840kb

input:

48 26 424594716

output:

362283012

result:

ok single line: '362283012'

Test #12:

score: 30
Accepted
time: 0ms
memory: 3684kb

input:

49 1000000000 738885247

output:

0

result:

ok single line: '0'

Test #13:

score: 30
Accepted
time: 1ms
memory: 3756kb

input:

48 39 688951620

output:

598399200

result:

ok single line: '598399200'

Test #14:

score: 30
Accepted
time: 0ms
memory: 3532kb

input:

50 476039414 292870080

output:

0

result:

ok single line: '0'

Test #15:

score: 30
Accepted
time: 2ms
memory: 3832kb

input:

50 48 245196368

output:

123576912

result:

ok single line: '123576912'

Subtask #4:

score: 50
Accepted

Test #16:

score: 50
Accepted
time: 0ms
memory: 3548kb

input:

150 526250070 197316869

output:

0

result:

ok single line: '0'

Test #17:

score: 50
Accepted
time: 81ms
memory: 3988kb

input:

149 116 671784452

output:

18945228

result:

ok single line: '18945228'

Test #18:

score: 50
Accepted
time: 76ms
memory: 4068kb

input:

146 144 906402626

output:

438777234

result:

ok single line: '438777234'

Test #19:

score: 50
Accepted
time: 80ms
memory: 3932kb

input:

147 143 705666477

output:

70408701

result:

ok single line: '70408701'

Test #20:

score: 50
Accepted
time: 80ms
memory: 4004kb

input:

150 147 453481175

output:

336290325

result:

ok single line: '336290325'