记录编号 583630 评测结果 AAAAAAAAAAAAAAAAAAAA
题目名称 Maximized Combos 最终得分 100
用户昵称 Gravataryrtiop 是否通过 通过
代码语言 C++ 运行时间 0.610 s
提交时间 2023-10-19 20:21:40 内存使用 6.68 MiB
显示代码纯文本
#include <bits/stdc++.h>
#define pb emplace_back
#define fir first
#define sec second

using i64 = long long;
using pii = std::pair<int, int>;

constexpr int maxn = 4e5 + 5, mod = 998244353;
int fac[maxn], ifac[maxn], n, m, s, ans[maxn], sum[maxn], sgn[maxn];
int power(int x, int y) {
	int ans = 1;
	for(;y;y >>= 1) {
		if(y & 1) ans = 1ll * ans * x % mod;
		x = 1ll * x * x % mod;
	}
	return ans;
}
void init(int n) {
	for(int i = fac[0] = 1;i <= n;++ i)
		fac[i] = 1ll * fac[i - 1] * i % mod;
	ifac[n] = power(fac[n], mod - 2);
	for(int i = n - 1;~ i;-- i)
		ifac[i] = 1ll * ifac[i + 1] * (i + 1) % mod;
	for(int i = sgn[0] = 1;i <= n;++ i)
		sgn[i] = mod - sgn[i - 1];
	return ;
}
int C(int n, int m) {
	if(n < 0||m < 0||n < m) return 0;
	return 1ll * fac[n] * ifac[n - m] % mod * ifac[m] % mod;
}

int main() {
	freopen("combos.in", "r", stdin);
	freopen("combos.out", "w", stdout);
	scanf("%d %d", &n, &m); init(2 * n);
	if(n == m) {
		for(int i = 1;i <= m;++ i)
			printf("%d\n", i == m);
		return 0;
	}
	for(int i = 0;i <= n;++ i) {
		sum[i] = C(n - m + i - 1, i);
		(sum[i] += sum[i - 1]) %= mod;
	}
	for(int s = 1;s <= m;++ s) {
		for(int i = 0;i <= n - m;++ i) {
			int t = i * (s + 1);
			if(t > m) break ;
			int coef = 1ll * sgn[i] * C(n - m, i) % mod;
			(ans[s] += 1ll * coef * sum[m - t] % mod) %= mod;
			if(m - t - s > 0) (ans[s] += mod - 1ll * coef * sum[m - t - s - 1] % mod) %= mod;
		}
	}
	for(int s = m;s >= 1;-- s)
		(ans[s] += mod - ans[s - 1]) %= mod;
	for(int s = 1;s <= m;++ s)
		printf("%d\n", ans[s]);
	return 0;
}