QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#284012 | #7774. 基础寄术练习题 | zzzYheng | 75 | 1392ms | 250804kb | C++17 | 1.9kb | 2023-12-15 20:49:16 | 2023-12-15 20:49:16 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int kMaxN = 105;
int n, m, k, p;
int getPow(int x, int y) {
int res = 1;
while (y) {
if (y & 1) res = res * x % p;
x = x * x % p;
y >>= 1;
}
return res;
}
void add(int &x, int y) {
x += y;
if (x >= p) x -= p;
if (x < 0) x += p;
}
namespace Task1 {
int inv[kMaxN];
int f[kMaxN][kMaxN];
int ans;
void main() {
for (int i = 1; i <= m; ++i) {
inv[i] = getPow(i, p - 2);
}
f[0][0] = 1;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
for (int k = 0; k < j; ++k) {
add(f[i][j], f[i - 1][k] * inv[j] % p);
}
}
}
for (int i = 1; i <= m; ++i) add(ans, f[n][i]);
cout << ans << '\n';
}
}
namespace Task2 {
const int kMaxN = 75;
int a1;
int inv[kMaxN * kMaxN];
int f[kMaxN][kMaxN][kMaxN * kMaxN];
int ans;
void work() {
memset(f, 0, sizeof(f));
f[0][0][a1] = 1;
for (int i = 1; i <= m; ++i) {
for (int j = 0; j < n; ++j) {
for (int k = a1; k <= n * m; ++k) {
// 没有取到 T 中
add(f[i][j][k], f[i - 1][j][k]);
if (i != a1) {
// 取到 T 中但没取到 S 中
if (j)
add(f[i][j][k], f[i - 1][j - 1][k] * inv[i] % p);
// 取到 T 中并且取到 S 中
if (j && k >= i)
add(f[i][j][k], -f[i - 1][j - 1][k - i] * inv[i] % p);
}
//cout << i << ' ' << j << ' ' << k << ' ' << f[i][j][k] << '\n';
}
}
}
int res = 0;
for (int s = a1; s <= n * m; ++s) {
add(res, f[m][n - 1][s] * inv[s] % p);
}
add(ans, res * a1 % p);
}
void main() {
for (int i = 1; i <= n * m; ++i) inv[i] = getPow(i, p - 2);
for (a1 = 1; a1 <= m; ++a1) {
work();
}
cout << ans << '\n';
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> m >> k >> p;
if (k == 1) Task1::main();
else Task2::main();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 1ms
memory: 3560kb
input:
9 16 1 327134593
output:
162102742
result:
ok single line: '162102742'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
11 18 1 834359503
output:
256188485
result:
ok single line: '256188485'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3504kb
input:
18 18 1 614802701
output:
552168146
result:
ok single line: '552168146'
Test #4:
score: 0
Accepted
time: 311ms
memory: 250788kb
input:
7 16 2 861918403
output:
306693876
result:
ok single line: '306693876'
Test #5:
score: 0
Accepted
time: 327ms
memory: 250744kb
input:
11 17 2 617904383
output:
393900291
result:
ok single line: '393900291'
Subtask #2:
score: 25
Accepted
Test #6:
score: 25
Accepted
time: 2ms
memory: 3640kb
input:
60 98 1 715015339
output:
690737273
result:
ok single line: '690737273'
Test #7:
score: 0
Accepted
time: 2ms
memory: 3672kb
input:
96 97 1 507892589
output:
481151247
result:
ok single line: '481151247'
Test #8:
score: 0
Accepted
time: 2ms
memory: 3592kb
input:
90 95 1 621080027
output:
255353202
result:
ok single line: '255353202'
Test #9:
score: 0
Accepted
time: 2ms
memory: 3624kb
input:
85 94 1 297115421
output:
122254364
result:
ok single line: '122254364'
Test #10:
score: 0
Accepted
time: 2ms
memory: 3596kb
input:
81 91 1 460412027
output:
148037986
result:
ok single line: '148037986'
Subtask #3:
score: 15
Accepted
Test #11:
score: 15
Accepted
time: 686ms
memory: 250740kb
input:
29 29 2 545875273
output:
171843225
result:
ok single line: '171843225'
Test #12:
score: 0
Accepted
time: 688ms
memory: 250780kb
input:
29 29 2 342070607
output:
291380196
result:
ok single line: '291380196'
Test #13:
score: 0
Accepted
time: 737ms
memory: 250804kb
input:
30 30 2 293965439
output:
148471965
result:
ok single line: '148471965'
Test #14:
score: 0
Accepted
time: 715ms
memory: 250684kb
input:
30 30 2 528219961
output:
203632962
result:
ok single line: '203632962'
Test #15:
score: 0
Accepted
time: 0ms
memory: 3540kb
input:
30 30 1 202836509
output:
158493990
result:
ok single line: '158493990'
Subtask #4:
score: 10
Accepted
Test #16:
score: 10
Accepted
time: 697ms
memory: 250700kb
input:
27 30 2 360712453
output:
80987914
result:
ok single line: '80987914'
Test #17:
score: 0
Accepted
time: 660ms
memory: 250728kb
input:
26 29 2 377615957
output:
278812897
result:
ok single line: '278812897'
Test #18:
score: 0
Accepted
time: 655ms
memory: 250792kb
input:
22 30 2 163686233
output:
19517828
result:
ok single line: '19517828'
Test #19:
score: 0
Accepted
time: 612ms
memory: 250712kb
input:
20 29 2 785657729
output:
713061509
result:
ok single line: '713061509'
Test #20:
score: 0
Accepted
time: 0ms
memory: 3544kb
input:
24 29 1 374090597
output:
312615700
result:
ok single line: '312615700'
Subtask #5:
score: 15
Accepted
Test #21:
score: 15
Accepted
time: 1036ms
memory: 250716kb
input:
29 38 2 909155077
output:
745973305
result:
ok single line: '745973305'
Test #22:
score: 0
Accepted
time: 1392ms
memory: 250752kb
input:
40 40 2 1067474879
output:
995503334
result:
ok single line: '995503334'
Test #23:
score: 0
Accepted
time: 1042ms
memory: 250744kb
input:
32 37 2 751116719
output:
699924081
result:
ok single line: '699924081'
Test #24:
score: 0
Accepted
time: 1058ms
memory: 250744kb
input:
33 37 2 496100951
output:
21741458
result:
ok single line: '21741458'
Test #25:
score: 0
Accepted
time: 1ms
memory: 3616kb
input:
34 38 1 499914887
output:
386116226
result:
ok single line: '386116226'
Subtask #6:
score: 0
Time Limit Exceeded
Test #26:
score: 0
Time Limit Exceeded
input:
57 66 2 767174999
output:
result:
Subtask #7:
score: 0
Runtime Error
Test #31:
score: 0
Runtime Error
input:
96 96 2 453296971