QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#491048#8635. 圆KiharaTouma#100 ✓56ms199532kbC++23835b2024-07-25 17:06:502024-07-25 17:06:51

Judging History

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

  • [2024-07-25 17:06:51]
  • 评测
  • 测评结果:100
  • 用时:56ms
  • 内存:199532kb
  • [2024-07-25 17:06:50]
  • 提交

answer

//qoj8635
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int N = 5010;
const ll P = 998244353;
int n;
ll f[N][N], ans, fac[N];

ll qp(ll x, ll y){
	ll ans = 1;
	while(y){
		if(y & 1){
			ans = ans * x % P;
		}
		x = x * x % P;
		y >>= 1;
	}
	return ans;
}

int main(){
	scanf("%d", &n);
	if(n <= 3){
		puts("1");
		return 0;
	}
	f[1][1] = fac[1] = 1;
	for(int i = 2; i <= n; ++ i){
		fac[i] = fac[i-1] * i % P;
		for(int j = 1; j <= n; ++ j){
			f[i][j] = (f[i-1][j-1] + f[i-2][j-1]) % P;
			if(i > 3) f[i][j] = (f[i][j] + f[i-3][j-1]) % P;
		}
	}
	for(int i = 1; i <= n; ++ i){
		ll tmp = (f[n-3][i-1] * 2 + f[n-4][i-1] + f[n-2][i]) % P;
		ans = (ans + tmp * i % P * fac[i-1] % P * fac[n-i] % P) % P;
	}
	printf("%lld\n", ans * qp(fac[n-1], P-2) % P);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

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

input:

3

output:

1

result:

ok 1 number(s): "1"

Test #2:

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

input:

4

output:

2

result:

ok 1 number(s): "2"

Test #3:

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

input:

6

output:

299473309

result:

ok 1 number(s): "299473309"

Test #4:

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

input:

10

output:

487238321

result:

ok 1 number(s): "487238321"

Test #5:

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

input:

100

output:

41620761

result:

ok 1 number(s): "41620761"

Test #6:

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

input:

200

output:

208771764

result:

ok 1 number(s): "208771764"

Test #7:

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

input:

500

output:

888621375

result:

ok 1 number(s): "888621375"

Test #8:

score: 10
Accepted
time: 46ms
memory: 192544kb

input:

4798

output:

319137015

result:

ok 1 number(s): "319137015"

Test #9:

score: 10
Accepted
time: 50ms
memory: 199532kb

input:

4999

output:

818467659

result:

ok 1 number(s): "818467659"

Test #10:

score: 10
Accepted
time: 56ms
memory: 199468kb

input:

5000

output:

142907477

result:

ok 1 number(s): "142907477"