QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#491038#8635. 圆KiharaTouma#30 65ms199580kbC++23819b2024-07-25 17:05:322024-07-25 17:05:34

Judging History

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

  • [2024-07-25 17:05:34]
  • 评测
  • 测评结果:30
  • 用时:65ms
  • 内存:199580kb
  • [2024-07-25 17:05:32]
  • 提交

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);
	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;
		// printf("%d %d\n", i, tmp);
		ans = (ans + tmp * i % P * fac[i-1] % P * fac[n-i] % P);
	}
	printf("%lld\n", ans * qp(fac[n-1], P-2) % P);
	return 0;
}

详细


Pretests


Final Tests

Test #1:

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

input:

3

output:

6

result:

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

Test #2:

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

input:

4

output:

2

result:

ok 1 number(s): "2"

Test #3:

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

input:

6

output:

299473309

result:

ok 1 number(s): "299473309"

Test #4:

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

input:

10

output:

487238321

result:

ok 1 number(s): "487238321"

Test #5:

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

input:

100

output:

107813204

result:

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

Test #6:

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

input:

200

output:

407349093

result:

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

Test #7:

score: 0
Wrong Answer
time: 4ms
memory: 22572kb

input:

500

output:

155146794

result:

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

Test #8:

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

input:

4798

output:

-43971448

result:

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

Test #9:

score: 0
Wrong Answer
time: 47ms
memory: 199532kb

input:

4999

output:

-129657375

result:

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

Test #10:

score: 0
Wrong Answer
time: 65ms
memory: 199580kb

input:

5000

output:

992693820

result:

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