记录编号 583571 评测结果 AAAAAAAAAAAAAAAAAAAA
题目名称 Maximized Combos 最终得分 100
用户昵称 Gravatarzxhhh 是否通过 通过
代码语言 C++ 运行时间 1.104 s
提交时间 2023-10-18 20:27:18 内存使用 9.12 MiB
显示代码纯文本
#include <bits/stdc++.h>

using namespace std;
const int N = 2e5+5, mod = 998244353;
typedef long long ll;
int n, m;  
ll fac[N], inv[N], f[N]; 
ll qpow (ll x, ll y) {
    ll res = 1;
    while (y) {
        if (y&1) res = res*x%mod; 
        x = x*x%mod; y >>= 1;
    }
    return res;
}
ll C (int x, int y) {
    return y > x ? 0 : fac[x]*inv[x-y]%mod*inv[y]%mod; 
}

int main () {
    freopen("combos.in", "r", stdin); 
    freopen("combos.out", "w", stdout); 
    cin >> n >> m;
    fac[0] = 1; 
    for (int i = 1;i <= n+1;i++) fac[i] = fac[i-1]*i%mod; 
    inv[n+1] = qpow(fac[n+1], mod-2); 
    for (int i = n+1;i;i--) inv[i-1] = inv[i]*i%mod; 
    f[m] = C(n, m); 
    for (int i = m-1;i >= 1;i--) {
        f[i] = C(n, m); 
        for (int j = 1;j <= n-m+1;j++) {
            if (n-i*j-j < n-m) break; 
            if (j&1) f[i] -= C(n-m+1, j)*C(n-i*j-j, n-m)%mod; 
            else f[i] += C(n-m+1, j)*C(n-i*j-j, n-m)%mod; 
            f[i] %= mod; 
        }
    }
    for (int i = 1;i <= m;i++) {
        ll ans = f[i]-f[i-1]; ans = ((ans%mod)+mod)%mod; 
        printf("%lld\n", ans); 
    }
    return 0;
}