QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#720539#8047. DFS Order 4qzez#WA 1386ms6340kbC++141.5kb2024-11-07 13:12:202024-11-07 13:12:21

Judging History

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

  • [2024-11-07 13:12:21]
  • 评测
  • 测评结果:WA
  • 用时:1386ms
  • 内存:6340kb
  • [2024-11-07 13:12:20]
  • 提交

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];
struct fastmod {
  typedef unsigned long long u64;
  typedef __uint128_t u128;

  int m;
  u64 b;

  fastmod(int m) : m(m), b(((u128)1 << 64) / m) {}
  int reduce(u64 a) {
    u64 q = ((u128)a * b) >> 64;
    int r = a - q * m;
    return r < m ? r : r - m;
  }
} z(2);
int main(){
    cin>>n>>mod;
    z=fastmod(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[j][i]=f[j-1][i-1];
            for(int k=1;k<=i-1;k++){
                f[j][i]=z.reduce(f[j][i]+1ll*f[1][k]*f[j-1][i-1-k]);
            }
            for(int k=1;k<i-1;k++){
                f[j][i]=z.reduce(f[j][i]+1ll*f[1][k]*f[j][i-1-k]);
            }
            (f[j][i]+=mod-f[j+1][i-1])%=mod;
            f[j][i]=1ll*f[j][i]*inv[i]%mod;
        }
    }
    int ans=1ll*f[1][n-1]*fac[n-1]%mod;
    cout<<ans<<endl;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4 114514199

output:

2

result:

ok 1 number(s): "2"

Test #2:

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

input:

10 998244353

output:

11033

result:

ok 1 number(s): "11033"

Test #3:

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

input:

100 1000000007

output:

270904395

result:

ok 1 number(s): "270904395"

Test #4:

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

input:

756 1001338769

output:

901942543

result:

ok 1 number(s): "901942543"

Test #5:

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

input:

793 1009036033

output:

301770320

result:

ok 1 number(s): "301770320"

Test #6:

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

input:

759 1005587659

output:

846376219

result:

ok 1 number(s): "846376219"

Test #7:

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

input:

773 1007855479

output:

1398019

result:

ok 1 number(s): "1398019"

Test #8:

score: 0
Accepted
time: 1136ms
memory: 5896kb

input:

751 1006730639

output:

321287237

result:

ok 1 number(s): "321287237"

Test #9:

score: 0
Accepted
time: 1270ms
memory: 5940kb

input:

778 1007760653

output:

430322899

result:

ok 1 number(s): "430322899"

Test #10:

score: 0
Accepted
time: 1386ms
memory: 6304kb

input:

798 1007543827

output:

688720826

result:

ok 1 number(s): "688720826"

Test #11:

score: 0
Accepted
time: 1353ms
memory: 6056kb

input:

796 1004841413

output:

258829347

result:

ok 1 number(s): "258829347"

Test #12:

score: 0
Accepted
time: 1255ms
memory: 6268kb

input:

775 1005185189

output:

744278608

result:

ok 1 number(s): "744278608"

Test #13:

score: 0
Accepted
time: 1373ms
memory: 6340kb

input:

800 1006012831

output:

508549367

result:

ok 1 number(s): "508549367"

Test #14:

score: -100
Wrong Answer
time: 0ms
memory: 3536kb

input:

1 1001338769

output:

0

result:

wrong answer 1st numbers differ - expected: '1', found: '0'