QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#357918 | #8047. DFS Order 4 | JerryTcl | AC ✓ | 136ms | 6604kb | C++20 | 792b | 2024-03-19 14:59:54 | 2024-03-19 14:59:55 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(0)->sync_with_stdio(0);
int n, Mod; cin >> n >> Mod; vector<int> iv(n);
vector<vector<int>> f(n + 1, vector<int>(n));
const auto &mt = [&](int x) { return x < 0 ? x + Mod : x; };
f[1][0] = 1, iv[1] = 1; long long fac = 1;
for(int i = 2; i < n; ++i) fac = fac * i % Mod,
iv[i] = 1ll * (Mod - Mod / i) * iv[Mod % i] % Mod;
for(int i = 2; i <= n; ++i)
for(int j = 0; i + j <= n; ++j) {
__int128_t ret = f[i - 1][0];
for(int k = 2; k < i - 1; ++k)
ret += 1ll * (f[k][0] - f[k][i + j - 1 - k]) * f[i - k][j];
f[i][j] = mt((int)(ret * iv[i + j - 1] % Mod));
}
printf("%d", (int)(f[n][0] * fac % Mod));
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3776kb
input:
4 114514199
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3720kb
input:
10 998244353
output:
11033
result:
ok 1 number(s): "11033"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3972kb
input:
100 1000000007
output:
270904395
result:
ok 1 number(s): "270904395"
Test #4:
score: 0
Accepted
time: 112ms
memory: 5912kb
input:
756 1001338769
output:
901942543
result:
ok 1 number(s): "901942543"
Test #5:
score: 0
Accepted
time: 135ms
memory: 6264kb
input:
793 1009036033
output:
301770320
result:
ok 1 number(s): "301770320"
Test #6:
score: 0
Accepted
time: 119ms
memory: 6256kb
input:
759 1005587659
output:
846376219
result:
ok 1 number(s): "846376219"
Test #7:
score: 0
Accepted
time: 125ms
memory: 6020kb
input:
773 1007855479
output:
1398019
result:
ok 1 number(s): "1398019"
Test #8:
score: 0
Accepted
time: 112ms
memory: 6012kb
input:
751 1006730639
output:
321287237
result:
ok 1 number(s): "321287237"
Test #9:
score: 0
Accepted
time: 128ms
memory: 6024kb
input:
778 1007760653
output:
430322899
result:
ok 1 number(s): "430322899"
Test #10:
score: 0
Accepted
time: 136ms
memory: 6296kb
input:
798 1007543827
output:
688720826
result:
ok 1 number(s): "688720826"
Test #11:
score: 0
Accepted
time: 136ms
memory: 6604kb
input:
796 1004841413
output:
258829347
result:
ok 1 number(s): "258829347"
Test #12:
score: 0
Accepted
time: 127ms
memory: 6052kb
input:
775 1005185189
output:
744278608
result:
ok 1 number(s): "744278608"
Test #13:
score: 0
Accepted
time: 134ms
memory: 6312kb
input:
800 1006012831
output:
508549367
result:
ok 1 number(s): "508549367"
Test #14:
score: 0
Accepted
time: 0ms
memory: 4032kb
input:
1 1001338769
output:
1
result:
ok 1 number(s): "1"
Test #15:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
2 1001338769
output:
1
result:
ok 1 number(s): "1"
Test #16:
score: 0
Accepted
time: 0ms
memory: 4084kb
input:
9 1009036033
output:
1780
result:
ok 1 number(s): "1780"
Test #17:
score: 0
Accepted
time: 0ms
memory: 4088kb
input:
14 1001338769
output:
43297358
result:
ok 1 number(s): "43297358"
Extra Test:
score: 0
Extra Test Passed