QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#284022#7774. 基础寄术练习题zzzYheng25 2ms3692kbC++171.9kb2023-12-15 20:55:452023-12-15 20:55:45

Judging History

你现在查看的是最新测评结果

  • [2023-12-15 20:55:45]
  • 评测
  • 测评结果:25
  • 用时:2ms
  • 内存:3692kb
  • [2023-12-15 20:55:45]
  • 提交

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][2];

int ans;

void work() {
	memset(f, 0, sizeof(f));
	f[0][0][0][0] = 1;
	for (int i = 1; i <= m; ++i) {
		for (int j = 0; j < n; ++j) {
			for (int k = a1; k <= n * m; ++k) {
				for (int t = 0; t < 2; ++t) {
					// 没有取到 T 中
					add(f[i][j][k][t], f[i - 1][j][k][t]);

					// 取到 T 中但没取到 S 中
					if (j)
						add(f[i][j][k][t], f[i - 1][j - 1][k][t] * inv[i] % p);
					// 取到 T 中并且取到 S 中
					if (j && k >= i) 
						add(f[i][j][k][t], -f[i - 1][j - 1][k - i][t] * inv[i] % p);
					// 取 i 作为 a1
					if (t && k >= i) {
						add(f[i][j][k][t], f[i - 1][j][k - i][0] * i % p);
					}
				}
			}
		}
	}
	for (int s = 1; s <= n * m; ++s) {
		add(ans, f[m][n - 1][s][1] * inv[s] % p);
	}
}

void main() {
	for (int i = 1; i <= n * m; ++i) inv[i] = getPow(i, p - 2);
	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: 0
Memory Limit Exceeded

Test #1:

score: 10
Accepted
time: 1ms
memory: 3584kb

input:

9 16 1 327134593

output:

162102742

result:

ok single line: '162102742'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3592kb

input:

11 18 1 834359503

output:

256188485

result:

ok single line: '256188485'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3472kb

input:

18 18 1 614802701

output:

552168146

result:

ok single line: '552168146'

Test #4:

score: -10
Memory Limit Exceeded

input:

7 16 2 861918403

output:

306693876

result:


Subtask #2:

score: 25
Accepted

Test #6:

score: 25
Accepted
time: 2ms
memory: 3624kb

input:

60 98 1 715015339

output:

690737273

result:

ok single line: '690737273'

Test #7:

score: 0
Accepted
time: 0ms
memory: 3592kb

input:

96 97 1 507892589

output:

481151247

result:

ok single line: '481151247'

Test #8:

score: 0
Accepted
time: 2ms
memory: 3692kb

input:

90 95 1 621080027

output:

255353202

result:

ok single line: '255353202'

Test #9:

score: 0
Accepted
time: 2ms
memory: 3580kb

input:

85 94 1 297115421

output:

122254364

result:

ok single line: '122254364'

Test #10:

score: 0
Accepted
time: 2ms
memory: 3464kb

input:

81 91 1 460412027

output:

148037986

result:

ok single line: '148037986'

Subtask #3:

score: 0
Memory Limit Exceeded

Test #11:

score: 0
Memory Limit Exceeded

input:

29 29 2 545875273

output:

171843225

result:


Subtask #4:

score: 0
Memory Limit Exceeded

Test #16:

score: 0
Memory Limit Exceeded

input:

27 30 2 360712453

output:

80987914

result:


Subtask #5:

score: 0
Memory Limit Exceeded

Test #21:

score: 0
Memory Limit Exceeded

input:

29 38 2 909155077

output:

745973305

result:


Subtask #6:

score: 0
Memory Limit Exceeded

Test #26:

score: 0
Memory Limit Exceeded

input:

57 66 2 767174999

output:

315351738

result:


Subtask #7:

score: 0
Memory Limit Exceeded

Test #31:

score: 0
Memory Limit Exceeded

input:

96 96 2 453296971

output:


result: