QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#838455#9561. 树数叔术eastcloud0 0ms3548kbC++232.6kb2024-12-31 11:42:132024-12-31 11:42:14

Judging History

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

  • [2024-12-31 11:42:14]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:3548kb
  • [2024-12-31 11:42:13]
  • 提交

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();
    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,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)));
            }
            g[op][j][k]=0;
        }
    }
    write(mul(f[(V)&1][n][0],fac[n]));
    return 0;
}

详细

Subtask #1:

score: 0
Time Limit Exceeded

Test #1:

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

input:

1 1 624295285

output:

0

result:

ok single line: '0'

Test #2:

score: 0
Time Limit Exceeded

input:

4 684813415 564954712

output:


result:


Subtask #2:

score: 0
Wrong Answer

Test #6:

score: 0
Wrong Answer
time: 0ms
memory: 3520kb

input:

6 4 956647977

output:

910239354

result:

wrong answer 1st lines differ - expected: '238320', found: '910239354'

Subtask #3:

score: 0
Wrong Answer

Test #11:

score: 0
Wrong Answer
time: 0ms
memory: 3536kb

input:

48 26 424594716

output:

117712140

result:

wrong answer 1st lines differ - expected: '362283012', found: '117712140'

Subtask #4:

score: 0
Runtime Error

Test #16:

score: 0
Runtime Error

input:

150 526250070 197316869

output:


result: