QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#399056#8047. DFS Order 4lifanAC ✓479ms6224kbC++141.5kb2024-04-25 21:15:542024-04-25 21:15:57

Judging History

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

  • [2024-04-25 21:15:57]
  • 评测
  • 测评结果:AC
  • 用时:479ms
  • 内存:6224kb
  • [2024-04-25 21:15:54]
  • 提交

answer

// 
/*
世界の果てさえ
【世界的尽头在何处】
仆らは知らない
【我们也无从知晓】
*/
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <random>
#include <ctime>
#define pr pair <int, int>
#define mr make_pair
#define LL long long
#define ls tree[p].L
#define rs tree[p].R
using namespace std;
const int MAXN = 805;
int n, Mod, invv[MAXN];
LL dp[MAXN][MAXN];
void read(int &x) {
	x = 0; bool f = 1; char C = getchar();
	for(; C < '0' || C > '9'; C = getchar()) if(C == '-') f = 0;
	for(; C >= '0' && C <= '9'; C = getchar()) x = (x << 1) + (x << 3) + (C ^ 48);
	x = (f ? x : -x);
}
LL Qpow(LL x, int y) {
	LL ans = 1;
	for(; y; y >>= 1) {
		if(y & 1) ans = ans * x % Mod;
		x = x * x % Mod;
	}
	return ans;
}
int main() {
	read(n); read(Mod); dp[1][0] = 1;
	for(int i = 1; i <= n; i ++) invv[i] = Qpow(i, Mod - 2);
	for(int i = 2; i <= n; i ++) {
		for(int j = 0; j <= n - i; j ++) {
			for(int k = 2; k <= i - 2; k ++) {
				dp[i][j] = (dp[i][j] + (dp[k][0] - dp[k][i - k - 1 + j]) * dp[i - k][j]) % Mod;
			}
//			printf("|%d %d %lld|\n", i, j, dp[i][j]);
			dp[i][j] = (dp[i - 1][0] + dp[i][j]) % Mod;
			dp[i][j] = dp[i][j] * invv[i + j - 1] % Mod;
//			printf("|%d %d %lld|\n", i, j, dp[i][j]);
		}
	}
	LL ans = dp[n][0];
	for(int i = 1; i <= n - 1; i ++) ans = ans * i % Mod;
	printf("%lld", (ans + Mod) % Mod);
	return 0;
}

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

详细

Test #1:

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

input:

4 114514199

output:

2

result:

ok 1 number(s): "2"

Test #2:

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

input:

10 998244353

output:

11033

result:

ok 1 number(s): "11033"

Test #3:

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

input:

100 1000000007

output:

270904395

result:

ok 1 number(s): "270904395"

Test #4:

score: 0
Accepted
time: 395ms
memory: 5832kb

input:

756 1001338769

output:

901942543

result:

ok 1 number(s): "901942543"

Test #5:

score: 0
Accepted
time: 462ms
memory: 6060kb

input:

793 1009036033

output:

301770320

result:

ok 1 number(s): "301770320"

Test #6:

score: 0
Accepted
time: 404ms
memory: 5828kb

input:

759 1005587659

output:

846376219

result:

ok 1 number(s): "846376219"

Test #7:

score: 0
Accepted
time: 427ms
memory: 6028kb

input:

773 1007855479

output:

1398019

result:

ok 1 number(s): "1398019"

Test #8:

score: 0
Accepted
time: 391ms
memory: 5880kb

input:

751 1006730639

output:

321287237

result:

ok 1 number(s): "321287237"

Test #9:

score: 0
Accepted
time: 440ms
memory: 6048kb

input:

778 1007760653

output:

430322899

result:

ok 1 number(s): "430322899"

Test #10:

score: 0
Accepted
time: 467ms
memory: 6088kb

input:

798 1007543827

output:

688720826

result:

ok 1 number(s): "688720826"

Test #11:

score: 0
Accepted
time: 468ms
memory: 6224kb

input:

796 1004841413

output:

258829347

result:

ok 1 number(s): "258829347"

Test #12:

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

input:

775 1005185189

output:

744278608

result:

ok 1 number(s): "744278608"

Test #13:

score: 0
Accepted
time: 479ms
memory: 6188kb

input:

800 1006012831

output:

508549367

result:

ok 1 number(s): "508549367"

Test #14:

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

input:

1 1001338769

output:

1

result:

ok 1 number(s): "1"

Test #15:

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

input:

2 1001338769

output:

1

result:

ok 1 number(s): "1"

Test #16:

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

input:

9 1009036033

output:

1780

result:

ok 1 number(s): "1780"

Test #17:

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

input:

14 1001338769

output:

43297358

result:

ok 1 number(s): "43297358"

Extra Test:

score: 0
Extra Test Passed