QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#389941 | #8047. DFS Order 4 | 5ab | AC ✓ | 494ms | 6220kb | C++20 | 1.9kb | 2024-04-14 21:25:34 | 2024-04-14 21:25:34 |
Judging History
answer
/* name: 8047
* author: 5ab
* created at: 2024-04-14
*/
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define ssz(x) (int((x).size()))
auto chmax = [](auto& x, auto y) { if (x < y) x = y; };
auto chmin = [](auto& x, auto y) { if (y < x) x = y; };
using ll = long long;
const int N = 800;
int f[N + 1][N + 1], fac[N + 1], ifac[N + 1], inv[N + 1];
ll qpow(ll bs, ll ix, int mod)
{
ll mul = bs, ret = 1;
while (ix)
{
if (ix & 1)
ret = (ret * mul) % mod;
mul = (mul * mul) % mod;
ix >>= 1;
}
return ret;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, mod;
cin >> n >> mod;
ll mmod = 1ll * mod * mod;
fac[0] = 1;
for (int i = 0; i < n; i++)
fac[i + 1] = 1ll * fac[i] * (i + 1) % mod;
ifac[n] = qpow(fac[n], mod - 2, mod);
for (int i = n; i > 0; i--)
{
ifac[i - 1] = 1ll * ifac[i] * i % mod;
inv[i] = 1ll * ifac[i] * fac[i - 1] % mod;
}
f[0][1] = f[1][0] = f[1][1] = 1;
for (int i = 2; i <= n; i++)
{
for (int j = 1; j <= i; j++)
f[i][j - 1] = 1ll * f[i - 1][j] * inv[i] % mod;
for (int j = 1; j <= i; j++)
{
ll sm = 0;
for (int k = 2; k < i; k++)
{
sm += 1ll * f[k - 1][1] * f[i - k][j];
if (sm >= mmod) sm -= mmod;
}
f[i][j] = (f[i][j] + sm % mod * inv[i]) % mod;
}
for (int j = 1; j < i; j++)
{
ll sm = 0;
for (int k = 1; k < i; k++)
{
sm += 1ll * f[k - 1][1] * f[i - k][j];
if (sm >= mmod) sm -= mmod;
}
f[i][j + 1] = (f[i][j + 1] - sm % mod * inv[i] % mod + mod) % mod;
}
f[i][1] = (f[i][1] + f[i][0]) % mod;
// cerr << i << " ";
// for (int j = 0; j <= i; j++)
// cerr << 1ll * f[i][j] * fac[i] % mod << " \n"[j == i];
}
cout << 1ll * f[n][0] * fac[n] % mod << endl;
return 0;
}
// started coding at: 04-14 19:59:40
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3712kb
input:
4 114514199
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3728kb
input:
10 998244353
output:
11033
result:
ok 1 number(s): "11033"
Test #3:
score: 0
Accepted
time: 1ms
memory: 4004kb
input:
100 1000000007
output:
270904395
result:
ok 1 number(s): "270904395"
Test #4:
score: 0
Accepted
time: 411ms
memory: 6048kb
input:
756 1001338769
output:
901942543
result:
ok 1 number(s): "901942543"
Test #5:
score: 0
Accepted
time: 480ms
memory: 6220kb
input:
793 1009036033
output:
301770320
result:
ok 1 number(s): "301770320"
Test #6:
score: 0
Accepted
time: 352ms
memory: 6052kb
input:
759 1005587659
output:
846376219
result:
ok 1 number(s): "846376219"
Test #7:
score: 0
Accepted
time: 442ms
memory: 6036kb
input:
773 1007855479
output:
1398019
result:
ok 1 number(s): "1398019"
Test #8:
score: 0
Accepted
time: 398ms
memory: 6048kb
input:
751 1006730639
output:
321287237
result:
ok 1 number(s): "321287237"
Test #9:
score: 0
Accepted
time: 447ms
memory: 6032kb
input:
778 1007760653
output:
430322899
result:
ok 1 number(s): "430322899"
Test #10:
score: 0
Accepted
time: 490ms
memory: 6124kb
input:
798 1007543827
output:
688720826
result:
ok 1 number(s): "688720826"
Test #11:
score: 0
Accepted
time: 483ms
memory: 6188kb
input:
796 1004841413
output:
258829347
result:
ok 1 number(s): "258829347"
Test #12:
score: 0
Accepted
time: 442ms
memory: 6128kb
input:
775 1005185189
output:
744278608
result:
ok 1 number(s): "744278608"
Test #13:
score: 0
Accepted
time: 494ms
memory: 6188kb
input:
800 1006012831
output:
508549367
result:
ok 1 number(s): "508549367"
Test #14:
score: 0
Accepted
time: 0ms
memory: 3684kb
input:
1 1001338769
output:
1
result:
ok 1 number(s): "1"
Test #15:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
2 1001338769
output:
1
result:
ok 1 number(s): "1"
Test #16:
score: 0
Accepted
time: 0ms
memory: 3768kb
input:
9 1009036033
output:
1780
result:
ok 1 number(s): "1780"
Test #17:
score: 0
Accepted
time: 0ms
memory: 3792kb
input:
14 1001338769
output:
43297358
result:
ok 1 number(s): "43297358"
Extra Test:
score: 0
Extra Test Passed