QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#720524#8047. DFS Order 4qzez#TL 1990ms6168kbC++141.5kb2024-11-07 13:08:132024-11-07 13:08:14

Judging History

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

  • [2024-11-07 13:08:14]
  • 评测
  • 测评结果:TL
  • 用时:1990ms
  • 内存:6168kb
  • [2024-11-07 13:08:13]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#ifdef DEBUG
template<class T>
ostream& operator << (ostream& out,vector<T>a){
    out<<'[';
    for(auto x:a)out<<x<<',';
    return out<<']';
}
template<class T>
auto ary(T *a,int l,int r){
    return vector<T>{a+l,a+1+r};
}
template<class T>
void debug(T x){
    cerr<<x<<endl;
}
template<class T,class...S>
void debug(T x,S...y){
    cerr<<x<<' ',debug(y...);
}
#else
#define debug(...) void()
#endif
const int N=805;
int n,mod,f[N][N],fac[N],inv[N];
int main(){
    cin>>n>>mod;
    inv[1]=1;
    for(int i=2;i<=n;i++)inv[i]=1ll*inv[mod%i]*(mod-mod/i)%mod;
    for(int i=fac[0]=1;i<=n;i++)fac[i]=1ll*fac[i-1]*i%mod;
    // f[1][1]=1;
    f[0][0]=1;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=i;j++){
            f[i][j]=(f[i][j]+f[i-1][j-1])%mod;
            for(int k=1;k<=i-1;k++){
                // if(i==3&&j==1)debug("A",f[k][1],f[i-1-k][j-1]);
                f[i][j]=(f[i][j]+1ll*f[k][1]*f[i-1-k][j-1])%mod;
            }
            for(int k=1;k<i-1;k++){
                // if(i==3&&j==1)debug("B",f[k][1],f[i-1-k][j]);
                f[i][j]=(f[i][j]+1ll*f[k][1]*f[i-1-k][j])%mod;
            }
            // if(i==3&&j==1)debug("C",-f[i-1][j+1]);
            (f[i][j]+=mod-f[i-1][j+1])%=mod;
            f[i][j]=1ll*f[i][j]*inv[i]%mod;
            // debug(i,j,1ll*f[i][j]*fac[i]%mod);
        }
    }
    int ans=1ll*f[n-1][1]*fac[n-1]%mod;
    cout<<ans<<endl;
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3712kb

input:

4 114514199

output:

2

result:

ok 1 number(s): "2"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3668kb

input:

10 998244353

output:

11033

result:

ok 1 number(s): "11033"

Test #3:

score: 0
Accepted
time: 4ms
memory: 4012kb

input:

100 1000000007

output:

270904395

result:

ok 1 number(s): "270904395"

Test #4:

score: 0
Accepted
time: 1723ms
memory: 5920kb

input:

756 1001338769

output:

901942543

result:

ok 1 number(s): "901942543"

Test #5:

score: 0
Accepted
time: 1990ms
memory: 6168kb

input:

793 1009036033

output:

301770320

result:

ok 1 number(s): "301770320"

Test #6:

score: 0
Accepted
time: 1744ms
memory: 6012kb

input:

759 1005587659

output:

846376219

result:

ok 1 number(s): "846376219"

Test #7:

score: 0
Accepted
time: 1843ms
memory: 5980kb

input:

773 1007855479

output:

1398019

result:

ok 1 number(s): "1398019"

Test #8:

score: 0
Accepted
time: 1694ms
memory: 5980kb

input:

751 1006730639

output:

321287237

result:

ok 1 number(s): "321287237"

Test #9:

score: 0
Accepted
time: 1875ms
memory: 6000kb

input:

778 1007760653

output:

430322899

result:

ok 1 number(s): "430322899"

Test #10:

score: -100
Time Limit Exceeded

input:

798 1007543827

output:

688720826

result: