QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#621571#8635. 圆Kryptonite40 77ms3804kbC++201.6kb2024-10-08 15:25:582024-10-08 15:25:58

Judging History

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

  • [2024-10-08 15:25:58]
  • 评测
  • 测评结果:40
  • 用时:77ms
  • 内存:3804kb
  • [2024-10-08 15:25:58]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int N = 5005;
const int mod = 998244353;

int n;
ll fac[N], inv[N], sum[N];

void add(ll &x, ll y) {
	x = x + y >= mod ? x + y - mod : x + y;
}

ll qpow(ll a, ll b) {
	ll res = 1;
	while (b) {
		if (b & 1) res = res * a % mod;
		b >>= 1;
		a = a * a % mod;
	}
	return res;
}

ll C(int x, int y) {
	if (x < y) return 0ll;
	return fac[x] * inv[y] % mod * inv[x - y] % mod;
}

int main() {
//	freopen("color.in", "r", stdin);
//	freopen("color.out", "w", stdout);
	
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	
	cin >> n;
	if (n == 3) {
		cout << 1;
		return 0;
	}
	// define the first step is on the first.
	fac[0] = inv[0] = 1;
	for (int i = 1; i <= n; ++i) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = qpow(fac[i], mod - 2);
	}
	for (int k = 1; k < n; ++k) {
		// calc the answer less than k yet the first one.
		ll g = 0;
		for (int ed = n - 2; ed <= n; ++ed) {
			int len = ed - 1;
			for (int a = 0; a <= len && a <= k; ++a) {
				int b2c = len - k;
				int bc = k - a;
				int c = b2c - bc;
				int b = k - a - c;
				if (b >= 0 && c >= 0) {
					g = (g + C(k, a) * C(k - a, b) % mod * fac[k] % mod);
				}
			}
		}
		sum[k + 1] = g * fac[n - k - 1] % mod;
	}
	ll ans = 0;
	for (int i = 1; i <= n; ++i) {
//		cout << i << " : " << sum[i] - sum[i - 1] << '\n';
		ll tmp = (sum[i] - sum[i - 1] + mod) * inv[n - 1] % mod;
//		cout << tmp << " ON EARTH.\n";
		ans = (ans + tmp * i % mod) % mod;
	}
	cout << ans;
	
	return 0;
}

詳細信息


Pretests


Final Tests

Test #1:

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

input:

3

output:

1

result:

ok 1 number(s): "1"

Test #2:

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

input:

4

output:

2

result:

ok 1 number(s): "2"

Test #3:

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

input:

6

output:

299473309

result:

ok 1 number(s): "299473309"

Test #4:

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

input:

10

output:

487238321

result:

ok 1 number(s): "487238321"

Test #5:

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

input:

100

output:

619956582

result:

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

Test #6:

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

input:

200

output:

62912752

result:

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

Test #7:

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

input:

500

output:

385240280

result:

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

Test #8:

score: 0
Wrong Answer
time: 68ms
memory: 3804kb

input:

4798

output:

907439198

result:

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

Test #9:

score: 0
Wrong Answer
time: 77ms
memory: 3788kb

input:

4999

output:

567332580

result:

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

Test #10:

score: 0
Wrong Answer
time: 77ms
memory: 3796kb

input:

5000

output:

902237910

result:

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