QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#851607 | #8047. DFS Order 4 | jiamengtong | TL | 1993ms | 8664kb | C++14 | 878b | 2025-01-10 21:03:01 | 2025-01-10 21:03:05 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define M 805
using namespace std;
int n, mod, mul[M], dp[M][M];
int qpow(int x, int ti)
{
int ret = 1;
while(ti)
{
if(ti & 1) ret = ret * x % mod;
x = x * x % mod;
ti >>= 1;
}
return ret;
}
signed main()
{
scanf("%lld%lld", &n, &mod);
if(n == 1) return puts("1"), 0;
mul[0] = 1;
for(int i = 1; i <= n; i++) mul[i] = mul[i - 1] * i % mod;
dp[0][0] = 1;
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= i; j++)
{
dp[i][j] = dp[i - 1][j - 1];
for(int k = 1; k < i; k++) (dp[i][j] += dp[k][1] * dp[i - k - 1][j - 1]) %= mod;
for(int k = 1; k < i - 1; k++) (dp[i][j] += dp[k][1] * dp[i - k - 1][j]) %= mod;
(dp[i][j] += mod - dp[i - 1][j + 1]) %= mod;
(dp[i][j] *= qpow(i, mod - 2)) %= mod;
}
}
printf("%lld\n", dp[n - 1][1] * mul[n - 1] % mod);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 4000kb
input:
4 114514199
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 0
Accepted
time: 0ms
memory: 4016kb
input:
10 998244353
output:
11033
result:
ok 1 number(s): "11033"
Test #3:
score: 0
Accepted
time: 5ms
memory: 4352kb
input:
100 1000000007
output:
270904395
result:
ok 1 number(s): "270904395"
Test #4:
score: 0
Accepted
time: 1719ms
memory: 8484kb
input:
756 1001338769
output:
901942543
result:
ok 1 number(s): "901942543"
Test #5:
score: 0
Accepted
time: 1958ms
memory: 8592kb
input:
793 1009036033
output:
301770320
result:
ok 1 number(s): "301770320"
Test #6:
score: 0
Accepted
time: 1718ms
memory: 8608kb
input:
759 1005587659
output:
846376219
result:
ok 1 number(s): "846376219"
Test #7:
score: 0
Accepted
time: 1816ms
memory: 8308kb
input:
773 1007855479
output:
1398019
result:
ok 1 number(s): "1398019"
Test #8:
score: 0
Accepted
time: 1661ms
memory: 8348kb
input:
751 1006730639
output:
321287237
result:
ok 1 number(s): "321287237"
Test #9:
score: 0
Accepted
time: 1839ms
memory: 8576kb
input:
778 1007760653
output:
430322899
result:
ok 1 number(s): "430322899"
Test #10:
score: 0
Accepted
time: 1993ms
memory: 8628kb
input:
798 1007543827
output:
688720826
result:
ok 1 number(s): "688720826"
Test #11:
score: 0
Accepted
time: 1979ms
memory: 8664kb
input:
796 1004841413
output:
258829347
result:
ok 1 number(s): "258829347"
Test #12:
score: 0
Accepted
time: 1827ms
memory: 8448kb
input:
775 1005185189
output:
744278608
result:
ok 1 number(s): "744278608"
Test #13:
score: -100
Time Limit Exceeded
input:
800 1006012831
output:
508549367