QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#547761#8047. DFS Order 4zqsAC ✓780ms4144kbC++14957b2024-09-05 09:32:192024-09-05 09:32:19

Judging History

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

  • [2024-09-05 09:32:19]
  • 评测
  • 测评结果:AC
  • 用时:780ms
  • 内存:4144kb
  • [2024-09-05 09:32:19]
  • 提交

answer

#include <cstdio>

int f[805][805], fact[805], inv[805], n, mod;
int qpow(int a, int b) {
	int res = 1;
	while (b) {
		if (b & 1) res = 1ll * res * a % mod;
		a = 1ll * a * a % mod, b >>= 1;
	}
	return res;
}

int main() {
	scanf("%d%d", &n, &mod);
	fact[0] = 1;
	for (int i = 1; i <= n; ++ i) fact[i] = 1ll * fact[i - 1] * i % mod, inv[i] = qpow(i, mod - 2);
	f[1][0] = 1, f[0][0] = 1;
	for (int i = 2; i < n; ++ i)
	for (int j = 0; j < n - i && j < i; ++ j) {
		if (j >= 1) {
			for (int k = 0; k < i - 1; ++ k)
				f[i][j] = (f[i][j] - 1ll * f[k][0] * f[i - k - 1][j - 1]) % mod;
		}
		for (int k = 1; k < i - 1; ++ k)
			f[i][j] = (f[i][j] + 1ll * f[k][0] * f[i - k - 1][j]) % mod;
		f[i][j] = (f[i][j] + f[i - 1][j + 1]) % mod;
		if (!j) f[i][j] = (f[i][j] + f[i - 1][j]) % mod;
		f[i][j] = 1ll * f[i][j] * inv[i] % mod;
	}
	int ans = 1ll * f[n - 1][0] * fact[n - 1] % mod;
	printf("%d", (ans + mod) % mod);
	return 0;
}

这程序好像有点Bug,我给组数据试试?

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 1612kb

input:

4 114514199

output:

2

result:

ok 1 number(s): "2"

Test #2:

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

input:

10 998244353

output:

11033

result:

ok 1 number(s): "11033"

Test #3:

score: 0
Accepted
time: 1ms
memory: 1892kb

input:

100 1000000007

output:

270904395

result:

ok 1 number(s): "270904395"

Test #4:

score: 0
Accepted
time: 653ms
memory: 3856kb

input:

756 1001338769

output:

901942543

result:

ok 1 number(s): "901942543"

Test #5:

score: 0
Accepted
time: 755ms
memory: 4132kb

input:

793 1009036033

output:

301770320

result:

ok 1 number(s): "301770320"

Test #6:

score: 0
Accepted
time: 665ms
memory: 3996kb

input:

759 1005587659

output:

846376219

result:

ok 1 number(s): "846376219"

Test #7:

score: 0
Accepted
time: 703ms
memory: 3896kb

input:

773 1007855479

output:

1398019

result:

ok 1 number(s): "1398019"

Test #8:

score: 0
Accepted
time: 645ms
memory: 3956kb

input:

751 1006730639

output:

321287237

result:

ok 1 number(s): "321287237"

Test #9:

score: 0
Accepted
time: 710ms
memory: 3912kb

input:

778 1007760653

output:

430322899

result:

ok 1 number(s): "430322899"

Test #10:

score: 0
Accepted
time: 774ms
memory: 4144kb

input:

798 1007543827

output:

688720826

result:

ok 1 number(s): "688720826"

Test #11:

score: 0
Accepted
time: 764ms
memory: 4144kb

input:

796 1004841413

output:

258829347

result:

ok 1 number(s): "258829347"

Test #12:

score: 0
Accepted
time: 709ms
memory: 4024kb

input:

775 1005185189

output:

744278608

result:

ok 1 number(s): "744278608"

Test #13:

score: 0
Accepted
time: 780ms
memory: 4124kb

input:

800 1006012831

output:

508549367

result:

ok 1 number(s): "508549367"

Test #14:

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

input:

1 1001338769

output:

1

result:

ok 1 number(s): "1"

Test #15:

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

input:

2 1001338769

output:

1

result:

ok 1 number(s): "1"

Test #16:

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

input:

9 1009036033

output:

1780

result:

ok 1 number(s): "1780"

Test #17:

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

input:

14 1001338769

output:

43297358

result:

ok 1 number(s): "43297358"

Extra Test:

score: 0
Extra Test Passed