QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#769895#8047. DFS Order 4songszhAC ✓490ms8548kbC++143.0kb2024-11-21 19:48:062024-11-21 19:48:08

Judging History

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

  • [2024-11-21 19:48:08]
  • 评测
  • 测评结果:AC
  • 用时:490ms
  • 内存:8548kb
  • [2024-11-21 19:48:06]
  • 提交

answer

#include <bits/stdc++.h>

#define int long long
#define ll long long
#define ull unsigned long long
#define db double
#define ld long double
#define rep(i,l,r) for (int i = (int)(l); i <= (int)(r); ++ i )
#define rep1(i,l,r) for (int i = (int)(l); i >= (int)(r); -- i )
#define il inline
#define fst first
#define snd second
#define ptc putchar
#define Yes ptc('Y'),ptc('e'),ptc('s'),puts("")
#define No ptc('N'),ptc('o'),puts("")
#define YES ptc('Y'),ptc('E'),ptc('S'),puts("")
#define NO ptc('N'),ptc('O'),puts("")
#define pb emplace_back
#define sz(x) (int)(x.size())
#define all(x) x.begin(),x.end()
#define get(x) ((x - 1) / len + 1)
#define debug() puts("------------")

using namespace std;
typedef pair<int,int> PII;
typedef pair<int,PII> PIII;
typedef pair<ll,ll> PLL;
namespace szhqwq {
    template<class T> il void read(T &x) {
        x = 0; T f = 1; char ch = getchar();
        while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
        while (ch >= '0' && ch <= '9') { x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar(); }
        x *= f;
    }
    template<class T,class... Args> il void read(T &x,Args &...x_) { read(x); read(x_...); }
    template<class T> il void print(T x) {
        if (x < 0) ptc('-'), x = -x; 
        if (x > 9) print(x / 10); ptc(x % 10 + '0');
    }
    template<class T,class T_> il void write(T x,T_ ch) { print(x); ptc(ch); }
    template<class T,class T_> il void chmax(T &x,T_ y) { x = max(x,y); }
    template<class T,class T_> il void chmin(T &x,T_ y) { x = min(x,y); }
    template<class T,class T_,class T__> il T qmi(T a,T_ b,T__ p) {
        T res = 1; while (b) {
            if (b & 1) res = res * a % p;
            a = a * a % p; b >>= 1;
        } return res;
    }
    template<class T> il T gcd(T a,T b) { if (!b) return a; return gcd(b,a % b); }
    template<class T,class T_> il void exgcd(T a, T b, T_ &x, T_ &y) {
        if (b == 0) { x = 1; y = 0; return; }
        exgcd(b,a % b,y,x); y -= a / b * x; return ;
    }
    template<class T,class T_> il T getinv(T x,T_ p) { T inv,y; exgcd(x,(T)p,inv,y); inv = (inv + p) % p; return inv; }
} using namespace szhqwq;
const int N = 810,inf = 1e9,mod = 998244353;
const ull base = 131,base_ = 233;
const ll inff = 1e18;
int n,p,f[N][N],invf[N];

il void solve() {
    //------------code------------
    read(n,p);
    invf[0] = invf[1] = 1;
    rep(i,2,n) invf[i] = (p - p / i) * invf[p % i] % p;
    // cerr << invf[2] << '\n';
    f[1][0] = 1;
    rep(i,2,n) rep(j,0,n - i) {
        f[i][j] = f[i - 1][0];
        rep(k,2,i - 1) f[i][j] = (f[i][j] + f[i - k][j] * (f[k][0] - f[k][i - 1 - k + j] + p) % p) % p;
        f[i][j] = f[i][j] * invf[i + j - 1] % p;
    }
    ll ans = f[n][0];
    rep(i,1,n) ans = ans * i % p;
    ans = ans * invf[n] % p;
    write(ans,'\n');
    return ;
}

il void init() {
    return ;
}

signed main() {
    // init();
    int _ = 1;
    // read(_);
    while (_ -- ) solve();
    return 0;
}

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

详细

Test #1:

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

input:

4 114514199

output:

2

result:

ok 1 number(s): "2"

Test #2:

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

input:

10 998244353

output:

11033

result:

ok 1 number(s): "11033"

Test #3:

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

input:

100 1000000007

output:

270904395

result:

ok 1 number(s): "270904395"

Test #4:

score: 0
Accepted
time: 412ms
memory: 8256kb

input:

756 1001338769

output:

901942543

result:

ok 1 number(s): "901942543"

Test #5:

score: 0
Accepted
time: 474ms
memory: 8524kb

input:

793 1009036033

output:

301770320

result:

ok 1 number(s): "301770320"

Test #6:

score: 0
Accepted
time: 420ms
memory: 8292kb

input:

759 1005587659

output:

846376219

result:

ok 1 number(s): "846376219"

Test #7:

score: 0
Accepted
time: 443ms
memory: 8296kb

input:

773 1007855479

output:

1398019

result:

ok 1 number(s): "1398019"

Test #8:

score: 0
Accepted
time: 408ms
memory: 7916kb

input:

751 1006730639

output:

321287237

result:

ok 1 number(s): "321287237"

Test #9:

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

input:

778 1007760653

output:

430322899

result:

ok 1 number(s): "430322899"

Test #10:

score: 0
Accepted
time: 485ms
memory: 8400kb

input:

798 1007543827

output:

688720826

result:

ok 1 number(s): "688720826"

Test #11:

score: 0
Accepted
time: 481ms
memory: 8200kb

input:

796 1004841413

output:

258829347

result:

ok 1 number(s): "258829347"

Test #12:

score: 0
Accepted
time: 447ms
memory: 8396kb

input:

775 1005185189

output:

744278608

result:

ok 1 number(s): "744278608"

Test #13:

score: 0
Accepted
time: 490ms
memory: 8548kb

input:

800 1006012831

output:

508549367

result:

ok 1 number(s): "508549367"

Test #14:

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

input:

1 1001338769

output:

1

result:

ok 1 number(s): "1"

Test #15:

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

input:

2 1001338769

output:

1

result:

ok 1 number(s): "1"

Test #16:

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

input:

9 1009036033

output:

1780

result:

ok 1 number(s): "1780"

Test #17:

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

input:

14 1001338769

output:

43297358

result:

ok 1 number(s): "43297358"

Extra Test:

score: 0
Extra Test Passed