QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#351674#8047. DFS Order 4GraphcityAC ✓1157ms6196kbC++201.1kb2024-03-12 10:58:062024-03-12 10:58:07

Judging History

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

  • [2024-03-12 10:58:07]
  • 评测
  • 测评结果:AC
  • 用时:1157ms
  • 内存:6196kb
  • [2024-03-12 10:58:06]
  • 提交

answer

#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rof(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
const int Maxn=800;

int f[Maxn+5][Maxn+5],iv[Maxn+5],n,Mod;

inline int Pow(int x,int y)
{
    int res=1;
    while(y)
    {
        if(y&1) res=1ll*res*x%Mod;
        x=1ll*x*x%Mod,y>>=1;
    }
    return res;
}

// inline int Fac(int x) {int res=1; For(i,1,x) res=1ll*res*i%Mod; return res;}

int main()
{
    // freopen("1.in","r",stdin);

    cin>>n>>Mod; f[1][0]=1;
    if(n==1) {puts("1"); return 0;}
    For(i,1,n) iv[i]=Pow(i,Mod-2);
    For(i,2,n) For(j,0,i-1)
    {
        f[i][j]=(j==0?1ll:Mod-1ll)*(f[i-j-1][0]+(j+1==i))%Mod*iv[i]%Mod;
        // if(i==3 && j==0) cerr<<f[i][j]*6%Mod<<endl;
        For(k,1,i-j-2) f[i][j]=(f[i][j]+1ll*f[i-k-1][j]*f[k][0]%Mod*iv[i])%Mod;
        // if(i==3 && j==0) cerr<<f[i][j]*6%Mod<<endl;
        For(k,1,i-j-2) f[i][j]=(f[i][j]+1ll*f[k+j][j]*f[i-1][j+k]%Mod*iv[i])%Mod;
        // cerr<<i<<' '<<j<<' '<<1ll*f[i][j]*Fac(i)%Mod<<endl;
    }
    int ans=f[n-1][0];
    For(i,1,n-1) ans=1ll*ans*i%Mod;
    cout<<ans<<endl;
    return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4 114514199

output:

2

result:

ok 1 number(s): "2"

Test #2:

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

input:

10 998244353

output:

11033

result:

ok 1 number(s): "11033"

Test #3:

score: 0
Accepted
time: 3ms
memory: 4008kb

input:

100 1000000007

output:

270904395

result:

ok 1 number(s): "270904395"

Test #4:

score: 0
Accepted
time: 977ms
memory: 6076kb

input:

756 1001338769

output:

901942543

result:

ok 1 number(s): "901942543"

Test #5:

score: 0
Accepted
time: 1124ms
memory: 5984kb

input:

793 1009036033

output:

301770320

result:

ok 1 number(s): "301770320"

Test #6:

score: 0
Accepted
time: 987ms
memory: 6008kb

input:

759 1005587659

output:

846376219

result:

ok 1 number(s): "846376219"

Test #7:

score: 0
Accepted
time: 1045ms
memory: 5984kb

input:

773 1007855479

output:

1398019

result:

ok 1 number(s): "1398019"

Test #8:

score: 0
Accepted
time: 956ms
memory: 5912kb

input:

751 1006730639

output:

321287237

result:

ok 1 number(s): "321287237"

Test #9:

score: 0
Accepted
time: 1067ms
memory: 6108kb

input:

778 1007760653

output:

430322899

result:

ok 1 number(s): "430322899"

Test #10:

score: 0
Accepted
time: 1146ms
memory: 6180kb

input:

798 1007543827

output:

688720826

result:

ok 1 number(s): "688720826"

Test #11:

score: 0
Accepted
time: 1139ms
memory: 6196kb

input:

796 1004841413

output:

258829347

result:

ok 1 number(s): "258829347"

Test #12:

score: 0
Accepted
time: 1053ms
memory: 5956kb

input:

775 1005185189

output:

744278608

result:

ok 1 number(s): "744278608"

Test #13:

score: 0
Accepted
time: 1157ms
memory: 6156kb

input:

800 1006012831

output:

508549367

result:

ok 1 number(s): "508549367"

Test #14:

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

input:

1 1001338769

output:

1

result:

ok 1 number(s): "1"

Test #15:

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

input:

2 1001338769

output:

1

result:

ok 1 number(s): "1"

Test #16:

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

input:

9 1009036033

output:

1780

result:

ok 1 number(s): "1780"

Test #17:

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

input:

14 1001338769

output:

43297358

result:

ok 1 number(s): "43297358"

Extra Test:

score: 0
Extra Test Passed