QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#766910#8047. DFS Order 4HildaHuAC ✓469ms8684kbC++141013b2024-11-20 19:14:182024-11-20 19:14:18

Judging History

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

  • [2024-11-20 19:14:18]
  • 评测
  • 测评结果:AC
  • 用时:469ms
  • 内存:8684kb
  • [2024-11-20 19:14:18]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
using namespace std;

const int N = 810;
int n, mod, f[N][N];
int inv[N];
int sub(int x, int y) {if ((x -= y) < 0) x += mod; return x; }
int power(int x, int y) {
	int ret = 1;
	while (y) {
		if (y & 1) ret = ret * x % mod;
		x = x * x % mod, y >>= 1;
	}
	return ret;
} 
int get_inv(int x) {return power(x, mod - 2); }
void init() {
	for (int i=1; i<=n; ++i)
		inv[i] = get_inv(i);
}

signed main() {
	ios :: sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> n >> mod;
	if (n == 1) {
		cout << "1\n"; return 0;
	}
	init();
	for (int j=0; 2+j<=n; ++j) f[2][j] = inv[j + 1];
	for (int i=3; i<=n; ++i)
		for (int j=0; i+j<=n; ++j) {
			f[i][j] = f[i - 1][0];
			for (int k=2; k<=i-2; ++k)
				f[i][j] = (f[i][j] + sub(f[k][0], f[k][i - 1 - k + j]) * f[i - k][j]) % mod;
			f[i][j] = f[i][j] * inv[i - 1 + j] % mod;
		}
	int ans = f[n][0];
	for (int i=1; i<n; ++i) ans = ans * i % mod;
	cout << ans << "\n";
	return 0;
}

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

详细

Test #1:

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

input:

4 114514199

output:

2

result:

ok 1 number(s): "2"

Test #2:

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

input:

10 998244353

output:

11033

result:

ok 1 number(s): "11033"

Test #3:

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

input:

100 1000000007

output:

270904395

result:

ok 1 number(s): "270904395"

Test #4:

score: 0
Accepted
time: 398ms
memory: 8088kb

input:

756 1001338769

output:

901942543

result:

ok 1 number(s): "901942543"

Test #5:

score: 0
Accepted
time: 459ms
memory: 8512kb

input:

793 1009036033

output:

301770320

result:

ok 1 number(s): "301770320"

Test #6:

score: 0
Accepted
time: 402ms
memory: 8060kb

input:

759 1005587659

output:

846376219

result:

ok 1 number(s): "846376219"

Test #7:

score: 0
Accepted
time: 426ms
memory: 8684kb

input:

773 1007855479

output:

1398019

result:

ok 1 number(s): "1398019"

Test #8:

score: 0
Accepted
time: 390ms
memory: 8312kb

input:

751 1006730639

output:

321287237

result:

ok 1 number(s): "321287237"

Test #9:

score: 0
Accepted
time: 435ms
memory: 8132kb

input:

778 1007760653

output:

430322899

result:

ok 1 number(s): "430322899"

Test #10:

score: 0
Accepted
time: 469ms
memory: 8272kb

input:

798 1007543827

output:

688720826

result:

ok 1 number(s): "688720826"

Test #11:

score: 0
Accepted
time: 459ms
memory: 8452kb

input:

796 1004841413

output:

258829347

result:

ok 1 number(s): "258829347"

Test #12:

score: 0
Accepted
time: 424ms
memory: 8300kb

input:

775 1005185189

output:

744278608

result:

ok 1 number(s): "744278608"

Test #13:

score: 0
Accepted
time: 469ms
memory: 8268kb

input:

800 1006012831

output:

508549367

result:

ok 1 number(s): "508549367"

Test #14:

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

input:

1 1001338769

output:

1

result:

ok 1 number(s): "1"

Test #15:

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

input:

2 1001338769

output:

1

result:

ok 1 number(s): "1"

Test #16:

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

input:

9 1009036033

output:

1780

result:

ok 1 number(s): "1780"

Test #17:

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

input:

14 1001338769

output:

43297358

result:

ok 1 number(s): "43297358"

Extra Test:

score: 0
Extra Test Passed