QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#804387 | #8047. DFS Order 4 | Galex | AC ✓ | 559ms | 6432kb | C++23 | 1.4kb | 2024-12-07 22:14:24 | 2024-12-07 22:14:26 |
Judging History
answer
#include <bits/stdc++.h>
#define LL long long
#define ULL unsigned long long
#define pii pair<int, int>
#define pll pair<LL, LL>
#define fi first
#define se second
#define mkp make_pair
#define sz(x) (int)x.size()
#define pb push_back
using namespace std;
bool Mst;
LL read() {
LL s = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9')
f = (ch == '-' ? -1 : 1), ch = getchar();
while (ch >= '0' && ch <= '9')
s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
return s * f;
}
int mod;
int qpow(int a, int b) {
int res = 1;
while (b) {
if (b & 1)
res = (LL)res * a % mod;
a = (LL)a * a % mod, b >>= 1;
}
return res;
}
auto fplus = [](int x, int y) {return x + y < mod ? x + y : x + y - mod;};
auto fminus = [](int x, int y) {return x >= y ? x - y : x + mod - y;};
auto Fplus = [](int &x, int y) {x = fplus(x, y);};
auto Fminus = [](int &x, int y) {x = fminus(x, y);};
int n, f[805][805];
bool Med;
signed main() {
n = read(), mod = read();
f[1][0] = 1;
for (int i = 2; i <= n; i++)
for (int x = 0; x <= n && x + i <= n; x++) {
int inv = qpow(i - 1 + x, mod - 2);
f[i][x] = f[i - 1][0];
for (int j = 2; j <= i - 2; j++)
Fplus(f[i][x], 1ll * f[i - j][x] % mod * fminus(f[j][0], f[j][i - j - 1 + x]) % mod);
f[i][x] = 1ll * f[i][x] * inv % mod;
}
int ans = f[n][0];
for (int i = 1; i < n; i++) ans = 1ll * ans * i % mod;
printf("%d\n", ans);
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3764kb
input:
4 114514199
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3908kb
input:
10 998244353
output:
11033
result:
ok 1 number(s): "11033"
Test #3:
score: 0
Accepted
time: 3ms
memory: 4120kb
input:
100 1000000007
output:
270904395
result:
ok 1 number(s): "270904395"
Test #4:
score: 0
Accepted
time: 480ms
memory: 6180kb
input:
756 1001338769
output:
901942543
result:
ok 1 number(s): "901942543"
Test #5:
score: 0
Accepted
time: 547ms
memory: 6428kb
input:
793 1009036033
output:
301770320
result:
ok 1 number(s): "301770320"
Test #6:
score: 0
Accepted
time: 477ms
memory: 6316kb
input:
759 1005587659
output:
846376219
result:
ok 1 number(s): "846376219"
Test #7:
score: 0
Accepted
time: 509ms
memory: 6192kb
input:
773 1007855479
output:
1398019
result:
ok 1 number(s): "1398019"
Test #8:
score: 0
Accepted
time: 467ms
memory: 6080kb
input:
751 1006730639
output:
321287237
result:
ok 1 number(s): "321287237"
Test #9:
score: 0
Accepted
time: 515ms
memory: 6240kb
input:
778 1007760653
output:
430322899
result:
ok 1 number(s): "430322899"
Test #10:
score: 0
Accepted
time: 551ms
memory: 6320kb
input:
798 1007543827
output:
688720826
result:
ok 1 number(s): "688720826"
Test #11:
score: 0
Accepted
time: 549ms
memory: 6432kb
input:
796 1004841413
output:
258829347
result:
ok 1 number(s): "258829347"
Test #12:
score: 0
Accepted
time: 513ms
memory: 6172kb
input:
775 1005185189
output:
744278608
result:
ok 1 number(s): "744278608"
Test #13:
score: 0
Accepted
time: 559ms
memory: 6296kb
input:
800 1006012831
output:
508549367
result:
ok 1 number(s): "508549367"
Test #14:
score: 0
Accepted
time: 0ms
memory: 3804kb
input:
1 1001338769
output:
1
result:
ok 1 number(s): "1"
Test #15:
score: 0
Accepted
time: 0ms
memory: 3764kb
input:
2 1001338769
output:
1
result:
ok 1 number(s): "1"
Test #16:
score: 0
Accepted
time: 0ms
memory: 3904kb
input:
9 1009036033
output:
1780
result:
ok 1 number(s): "1780"
Test #17:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
14 1001338769
output:
43297358
result:
ok 1 number(s): "43297358"
Extra Test:
score: 0
Extra Test Passed