QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#591526#8635. 圆xiay40 51ms101684kbC++141.2kb2024-09-26 16:18:162024-09-26 16:18:17

Judging History

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

  • [2024-09-26 16:18:17]
  • 评测
  • 测评结果:40
  • 用时:51ms
  • 内存:101684kb
  • [2024-09-26 16:18:16]
  • 提交

answer

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

const int N = 5000 + 5, P = 998244353;
int dp[N][N];
int n;
long long fac[N];

long long qpow(long long a, int b) {
	long long ans = 1;
	while (b) {
		if (b & 1) {
			ans = ans * a % P;
		}
		a = a * a % P;
		b >>= 1;
	}
	return ans;
}

void init() {
	fac[0] = 1;
	for (int i = 1; i <= n; i++) {
		fac[i] = fac[i - 1] * i % P;
	}
}

long long C(int n, int m) {
	return fac[n] * qpow(fac[n - m], P - 2) % P * qpow(fac[m], P - 2) % P;
}

int main() {
	#ifndef ONLINE_JUDGE
	freopen("test.in", "r", stdin);
	freopen("test.out", "w", stdout);
	#endif

	scanf("%d", &n);
	if (n == 3) {
		puts("1");
		return 0;
	}
	init();
	dp[0][0] = 1;
	dp[1][1] = 1;
	for (int i = 2; i < n; i++) {
		for (int j = 1; j <= n; j++) {
			dp[i][j] = dp[i - 1][j - 1];
			if (i == 2) {
				(dp[i][j] += dp[i - 2][j - 1]) %= P;
			}
			else {
				(dp[i][j] += (dp[i - 2][j - 1] + dp[i - 3][j - 1]) % P) %= P;
			}
		}
	}
	int ans = 2;
	for (int i = 1; i < n; i++) {
		ans = (ans + 1ll * (C(n - 1, i) - (dp[n - 1][i] + dp[n - 2][i] + dp[n - 3][i]) % P + P) % P * fac[i] % P * fac[n - i - 1] % P * qpow(fac[n - 1], P - 2) % P) % P;
	}
	printf("%d\n", ans);

	return 0;
}

详细


Pretests


Final Tests

Test #1:

score: 10
Accepted
time: 0ms
memory: 3824kb

input:

3

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 10
Accepted
time: 0ms
memory: 3868kb

input:

4

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: 10
Accepted
time: 0ms
memory: 3944kb

input:

6

output:

299473309

result:

ok 1 number(s): "299473309"

Test #4:

score: 10
Accepted
time: 0ms
memory: 3872kb

input:

10

output:

487238321

result:

ok 1 number(s): "487238321"

Test #5:

score: 0
Wrong Answer
time: 1ms
memory: 6320kb

input:

100

output:

514146577

result:

wrong answer 1st numbers differ - expected: '41620761', found: '514146577'

Test #6:

score: 0
Wrong Answer
time: 1ms
memory: 8120kb

input:

200

output:

916603864

result:

wrong answer 1st numbers differ - expected: '208771764', found: '916603864'

Test #7:

score: 0
Wrong Answer
time: 0ms
memory: 14336kb

input:

500

output:

474513231

result:

wrong answer 1st numbers differ - expected: '888621375', found: '474513231'

Test #8:

score: 0
Wrong Answer
time: 42ms
memory: 98904kb

input:

4798

output:

933736123

result:

wrong answer 1st numbers differ - expected: '319137015', found: '933736123'

Test #9:

score: 0
Wrong Answer
time: 51ms
memory: 101684kb

input:

4999

output:

201372369

result:

wrong answer 1st numbers differ - expected: '818467659', found: '201372369'

Test #10:

score: 0
Wrong Answer
time: 48ms
memory: 101656kb

input:

5000

output:

886826040

result:

wrong answer 1st numbers differ - expected: '142907477', found: '886826040'