QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#547494#8047. DFS Order 4rqoi031AC ✓274ms4280kbC++141.2kb2024-09-04 22:07:482024-09-04 22:07:49

Judging History

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

  • [2024-09-04 22:07:49]
  • 评测
  • 测评结果:AC
  • 用时:274ms
  • 内存:4280kb
  • [2024-09-04 22:07:48]
  • 提交

answer

#include<stdio.h>
#include<algorithm>
typedef unsigned int uint;
typedef unsigned long long ull;
typedef __uint128_t ulll;
uint inv[805],dp[805][805];
int main() {
    int n;uint mod;
    scanf("%d%u",&n,&mod),--n;
    const uint len(std::__lg(mod-1)+1);
    const ull mul(((ulll(1)<<63+len)-1)/mod+1);
    const auto divide([&](const ull &x)->ull {
        return ulll(x)*mul>>63+len;
    });
    const auto reduce([&](const ull &x)->uint {
        return x-divide(x)*mod;
    });
    inv[0]=0,inv[1]=1;
    for(int i=2;i<=n;i++) {
        const int j(mod/i+1);
        inv[i]=reduce(ull(j)*inv[i*j-mod]);
    }
    for(int i=0;i<=n;i++) {
        dp[0][i]=1;
        dp[1][i]=inv[i+1];
    }
    for(int i=2;i<=n;i++) {
        for(int j=0;i+j<=n;j++) {
            dp[i][j]=reduce(dp[i][j]+ull(dp[0][j])*dp[i-1][0]);
            for(int k=1;k<i-1;k++) {
                dp[i][j]=reduce(dp[i][j]+ull(dp[k][j])*(dp[i-k-1][0]+mod-dp[i-k-1][j+k]));
            }
            dp[i][j]=reduce(ull(dp[i][j])*inv[i+j]%mod);
        }
    }
    uint ans(dp[n][0]);
    for(int i=1;i<=n;i++) {
        ans=reduce(ull(ans)*i);
    }
    printf("%u\n",ans);
    return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4 114514199

output:

2

result:

ok 1 number(s): "2"

Test #2:

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

input:

10 998244353

output:

11033

result:

ok 1 number(s): "11033"

Test #3:

score: 0
Accepted
time: 1ms
memory: 2052kb

input:

100 1000000007

output:

270904395

result:

ok 1 number(s): "270904395"

Test #4:

score: 0
Accepted
time: 231ms
memory: 4144kb

input:

756 1001338769

output:

901942543

result:

ok 1 number(s): "901942543"

Test #5:

score: 0
Accepted
time: 269ms
memory: 4228kb

input:

793 1009036033

output:

301770320

result:

ok 1 number(s): "301770320"

Test #6:

score: 0
Accepted
time: 235ms
memory: 4168kb

input:

759 1005587659

output:

846376219

result:

ok 1 number(s): "846376219"

Test #7:

score: 0
Accepted
time: 238ms
memory: 4108kb

input:

773 1007855479

output:

1398019

result:

ok 1 number(s): "1398019"

Test #8:

score: 0
Accepted
time: 216ms
memory: 4096kb

input:

751 1006730639

output:

321287237

result:

ok 1 number(s): "321287237"

Test #9:

score: 0
Accepted
time: 251ms
memory: 4112kb

input:

778 1007760653

output:

430322899

result:

ok 1 number(s): "430322899"

Test #10:

score: 0
Accepted
time: 264ms
memory: 4280kb

input:

798 1007543827

output:

688720826

result:

ok 1 number(s): "688720826"

Test #11:

score: 0
Accepted
time: 270ms
memory: 4240kb

input:

796 1004841413

output:

258829347

result:

ok 1 number(s): "258829347"

Test #12:

score: 0
Accepted
time: 245ms
memory: 4232kb

input:

775 1005185189

output:

744278608

result:

ok 1 number(s): "744278608"

Test #13:

score: 0
Accepted
time: 274ms
memory: 4276kb

input:

800 1006012831

output:

508549367

result:

ok 1 number(s): "508549367"

Test #14:

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

input:

1 1001338769

output:

1

result:

ok 1 number(s): "1"

Test #15:

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

input:

2 1001338769

output:

1

result:

ok 1 number(s): "1"

Test #16:

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

input:

9 1009036033

output:

1780

result:

ok 1 number(s): "1780"

Test #17:

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

input:

14 1001338769

output:

43297358

result:

ok 1 number(s): "43297358"

Extra Test:

score: 0
Extra Test Passed