QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#501581#8047. DFS Order 4WilliamxzhAC ✓492ms8700kbC++231.1kb2024-08-02 21:00:482024-08-02 21:00:49

Judging History

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

  • [2024-08-02 21:00:49]
  • 评测
  • 测评结果:AC
  • 用时:492ms
  • 内存:8700kb
  • [2024-08-02 21:00:48]
  • 提交

answer

#include <bits/stdc++.h>
#define il inline
using namespace std;
typedef long long ll;ll mod;
il void add(ll &x,ll y){x=(x+y>=mod?x+y-mod:x+y);}
il void del(ll &x,ll y){x=(x<y?x-y+mod:x-y);}
il ll qp(ll a,ll b){
    ll ans=1ll;
    while(b){
        if(b&1) ans=(ans*a)%mod;
        a=(a*a)%mod,b>>=1;
    }return ans;
}
const int N=803;
int n;ll f[N][N],fac[N],inv[N];
il void init(){
    fac[0]=1ll;for(int i=1;i<=n;++i) fac[i]=(fac[i-1]*1ll*i)%mod;
    for(int i=1;i<=n;++i) inv[i]=qp(i,mod-2ll);
}
int main(){
    //freopen("qoj8047_0.in","r",stdin);
    scanf("%d%lld",&n,&mod);init();if(n<=1){printf("1");exit(0);}
    f[1][0]=1ll;
    for(int i=2;i<n;++i)
        for(int k=0;k<=i;++k){
            f[i][k]=f[i-1][k+1];
            if(!k) add(f[i][0],f[i-1][0]);
            for(int j=1;j<=i-k;++j){
                add(f[i][k],f[j-1][0]*f[i-j][k]%mod);
                if(k) del(f[i][k],(f[j-1][0]+(j==1))*f[i-j][k-1]%mod);
            }
            f[i][k]=(f[i][k]*inv[i])%mod;
        }

    printf("%lld",f[n-1][0]*fac[n-1]%mod);
    return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4 114514199

output:

2

result:

ok 1 number(s): "2"

Test #2:

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

input:

10 998244353

output:

11033

result:

ok 1 number(s): "11033"

Test #3:

score: 0
Accepted
time: 2ms
memory: 6264kb

input:

100 1000000007

output:

270904395

result:

ok 1 number(s): "270904395"

Test #4:

score: 0
Accepted
time: 441ms
memory: 8120kb

input:

756 1001338769

output:

901942543

result:

ok 1 number(s): "901942543"

Test #5:

score: 0
Accepted
time: 476ms
memory: 8644kb

input:

793 1009036033

output:

301770320

result:

ok 1 number(s): "301770320"

Test #6:

score: 0
Accepted
time: 421ms
memory: 8628kb

input:

759 1005587659

output:

846376219

result:

ok 1 number(s): "846376219"

Test #7:

score: 0
Accepted
time: 444ms
memory: 8420kb

input:

773 1007855479

output:

1398019

result:

ok 1 number(s): "1398019"

Test #8:

score: 0
Accepted
time: 407ms
memory: 8408kb

input:

751 1006730639

output:

321287237

result:

ok 1 number(s): "321287237"

Test #9:

score: 0
Accepted
time: 454ms
memory: 8544kb

input:

778 1007760653

output:

430322899

result:

ok 1 number(s): "430322899"

Test #10:

score: 0
Accepted
time: 489ms
memory: 8660kb

input:

798 1007543827

output:

688720826

result:

ok 1 number(s): "688720826"

Test #11:

score: 0
Accepted
time: 487ms
memory: 8552kb

input:

796 1004841413

output:

258829347

result:

ok 1 number(s): "258829347"

Test #12:

score: 0
Accepted
time: 448ms
memory: 8536kb

input:

775 1005185189

output:

744278608

result:

ok 1 number(s): "744278608"

Test #13:

score: 0
Accepted
time: 492ms
memory: 8700kb

input:

800 1006012831

output:

508549367

result:

ok 1 number(s): "508549367"

Test #14:

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

input:

1 1001338769

output:

1

result:

ok 1 number(s): "1"

Test #15:

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

input:

2 1001338769

output:

1

result:

ok 1 number(s): "1"

Test #16:

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

input:

9 1009036033

output:

1780

result:

ok 1 number(s): "1780"

Test #17:

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

input:

14 1001338769

output:

43297358

result:

ok 1 number(s): "43297358"

Extra Test:

score: 0
Extra Test Passed