QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#488956#8815. Space StationZ_drjWA 1ms1672kbC++141.2kb2024-07-24 16:42:572024-07-24 16:42:58

Judging History

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

  • [2024-07-30 16:51:06]
  • hack成功,自动添加数据
  • (/hack/760)
  • [2024-07-24 16:42:58]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:1672kb
  • [2024-07-24 16:42:57]
  • 提交

answer

#include <cstdio>
#include <algorithm>

using i64 = long long;

const int N = 105;
const int mod = 998244353;

int n, m;
int a[N], mx;

i64 qpow(i64 a, i64 b = mod - 2) {
	i64 ans = 1;
	for (; b; b >>= 1, a = a * a % mod) {
		if (b & 1) {
			ans = ans * a % mod;
		}
	}
	return ans;
}

i64 fac[N], inv[N];
void prework() {
	fac[0] = inv[0] = inv[1] = 1;
	for (int i = 1; i <= n; i++) {
		fac[i] = fac[i - 1] * i % mod;
	}

	for (int i = 2; i <= n; i++) {
		inv[i] = (mod - mod / i) * inv[mod % i] % mod;
	}
	
	for (int i = 1; i <= n; i++) {
		inv[i] = inv[i] * inv[i - 1] % mod;
	}
}

i64 invC(int x, int y) {
	return inv[x] * fac[y] % mod * fac[x - y] % mod;
}

i64 f[N][N * N * 2];

int main() {
	scanf("%d %d", &n, &m);

	for (int i = 1; i <= n; i++) {
		scanf("%d", a + i);
		mx += a[i];
	}

	prework();

	f[0][0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j = n; j >= 1; j--) {
			for (int k = a[i]; k <= mx; k++) {
				f[j][k] = (f[j][k] + f[j - 1][k - a[i]]) % mod;
			}
		}
	}

	i64 ans = 0;	
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= mx; j++) {
			ans = (ans + invC(n, i) * f[i][j] % mod * std::min(j, i * m) * qpow(i) % mod) % mod;
		}
	}

	printf("%lld", ans);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3 3
2 3 4

output:

499122185

result:

ok 1 number(s): "499122185"

Test #2:

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

input:

5 1
10 20 30 40 50

output:

5

result:

ok 1 number(s): "5"

Test #3:

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

input:

1 9
37

output:

9

result:

ok 1 number(s): "9"

Test #4:

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

input:

5 5
24 41 29 6 40

output:

25

result:

ok 1 number(s): "25"

Test #5:

score: -100
Wrong Answer
time: 1ms
memory: 1672kb

input:

10 34
91 86 1 14 98 13 85 64 91 20

output:

279265694

result:

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