QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#387472#8047. DFS Order 4zjy0001AC ✓111ms6380kbC++17957b2024-04-12 15:36:112024-04-12 15:36:11

Judging History

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

  • [2024-04-12 15:36:11]
  • 评测
  • 测评结果:AC
  • 用时:111ms
  • 内存:6380kb
  • [2024-04-12 15:36:11]
  • 提交

answer

#include<bits/stdc++.h>
#define LL long long
#define LLL __int128
#define uint unsigned
#define ldb long double
#define uLL unsigned long long
using namespace std;
const int N=805;
int n,P,frc[N],inv[N],ivf[N],F[N][N];
inline int qpow(int x,int y,int z=1){
	for(;y;(y>>=1)&&(x=(LL)x*x%P))if(y&1)z=(LL)z*x%P;return z;
}
inline void init(const int&n){
    frc[0]=1,frc[1]=1,inv[1]=1;
    for(int i=2;i<=n;++i)frc[i]=1ll*frc[i-1]*i%P,inv[i]=-P/i*(LL)inv[P%i]%P;
    ivf[n]=qpow(frc[n],P-2);
    for(int i=n;i>=1;--i)ivf[i-1]=1ll*ivf[i]*i%P;
}
signed main(){
    cin.tie(0)->sync_with_stdio(0);
    cin>>n>>P,init(n),F[1][0]=1;
    for(int i=2;i<=n;++i)
        for(int j=0;j<=n-i;++j){
            LLL t=F[i-1][0];
            for(int k=2;k<=i-2;++k)
                t+=1ll*(F[k][0]-F[k][i+j-1-k])*F[i-k][j];
            F[i][j]=t*inv[i+j-1]%P;
        }
    int ans=1ll*F[n][0]*frc[n-1]%P;cout<<(ans<0?ans+P:ans);
    return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4 114514199

output:

2

result:

ok 1 number(s): "2"

Test #2:

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

input:

10 998244353

output:

11033

result:

ok 1 number(s): "11033"

Test #3:

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

input:

100 1000000007

output:

270904395

result:

ok 1 number(s): "270904395"

Test #4:

score: 0
Accepted
time: 91ms
memory: 6228kb

input:

756 1001338769

output:

901942543

result:

ok 1 number(s): "901942543"

Test #5:

score: 0
Accepted
time: 91ms
memory: 6380kb

input:

793 1009036033

output:

301770320

result:

ok 1 number(s): "301770320"

Test #6:

score: 0
Accepted
time: 92ms
memory: 5976kb

input:

759 1005587659

output:

846376219

result:

ok 1 number(s): "846376219"

Test #7:

score: 0
Accepted
time: 95ms
memory: 6020kb

input:

773 1007855479

output:

1398019

result:

ok 1 number(s): "1398019"

Test #8:

score: 0
Accepted
time: 79ms
memory: 6140kb

input:

751 1006730639

output:

321287237

result:

ok 1 number(s): "321287237"

Test #9:

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

input:

778 1007760653

output:

430322899

result:

ok 1 number(s): "430322899"

Test #10:

score: 0
Accepted
time: 109ms
memory: 6044kb

input:

798 1007543827

output:

688720826

result:

ok 1 number(s): "688720826"

Test #11:

score: 0
Accepted
time: 108ms
memory: 6152kb

input:

796 1004841413

output:

258829347

result:

ok 1 number(s): "258829347"

Test #12:

score: 0
Accepted
time: 99ms
memory: 6024kb

input:

775 1005185189

output:

744278608

result:

ok 1 number(s): "744278608"

Test #13:

score: 0
Accepted
time: 111ms
memory: 6092kb

input:

800 1006012831

output:

508549367

result:

ok 1 number(s): "508549367"

Test #14:

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

input:

1 1001338769

output:

1

result:

ok 1 number(s): "1"

Test #15:

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

input:

2 1001338769

output:

1

result:

ok 1 number(s): "1"

Test #16:

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

input:

9 1009036033

output:

1780

result:

ok 1 number(s): "1780"

Test #17:

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

input:

14 1001338769

output:

43297358

result:

ok 1 number(s): "43297358"

Extra Test:

score: 0
Extra Test Passed