Problem p02990 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define rep(i, b) FOR(i, 0, b)
#define INF mugen
#define dump(x) cerr << #x << "=" << x << endl
#define ALL(a) (a).begin(), (a).end()
#define EACH(e, v) for (auto &e : v)
#define SORT(v) sort(ALL(v))
#define PERM(v)                                                                \
  SORT(v);                                                                     \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(v)))
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
typedef pair<int, int> P;
template <class T> void chmin(T &a, T const &b) {
  if (b < a)
    a = b;
}
template <class T> void chmax(T &a, T const &b) {
  if (b > a)
    a = b;
}
template <typename T> string to_string(const T &n) {
  ostringstream stm;
  stm << n;
  return stm.str();
}
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
using ll = long long;
const ll mod = 1000'000'007;
#define int long long
ll mod_pow(ll a, ll b, ll r) {
  return b <= 0 ? 1 : (b % 2 ? a : 1) * mod_pow(a * a % r, b / 2, r) % r;
}

vector<ll> fac(112345678);  // n!(mod M)
vector<ll> ifac(112345678); // k!^{M-2} (mod M)

ll comb(ll a, ll b, ll M) { // aCbをmod計算
  if (a == 0 && b == 0)
    return 1;
  if (a < b || a < 0)
    return 0;
  ll tmp = ifac[a - b] * ifac[b] % M;
  return tmp * fac[a] % M;
}

ll dupc(ll a, ll b, ll M) {
  if (a == 0 && b == 0)
    return 1;
  if (a < 0 || b == 0)
    return 0;
  ll tmp = ifac[a - 1] * ifac[b] % M;
  return tmp * fac[a + b - 1] % M;
}
vector<vector<ll>> cmemo;
ll combbi(int n, int k, int MOD) {
  if (k == 0 || n == k)
    return cmemo[n][k] = 1;
  if (cmemo[n][k])
    return cmemo[n][k];
  if (n < k)
    return 0;
  return cmemo[n][k] =
             ((combbi(n - 1, k - 1, MOD) + combbi(n - 1, k, MOD)) % MOD);
}
signed main() {
  ll n, k, ans = 0LL;
  cin >> n >> k;

  fac[0] = 1;
  ifac[0] = 1;
  for (ll i = 0; i < 112345; i++) {
    fac[i + 1] = fac[i] * (i + 1) % mod;                  // n!(mod M)
    ifac[i + 1] = ifac[i] * mod_pow(i + 1, mod - 2, mod); // k!^{M-2} (mod M)
  }
  cmemo.assign(n + 1, vector<ll>(n + 1, 0));

  // dump(comb(4,2,mod));

  for (int i = 1; i <= k; i++) {
    ans = 0LL;
    {
      int bres = k - i;
      int rres = n - k - (i - 1);

      ans += combbi(rres + i, i, mod) % mod;
      ans *= combbi(bres + i - 1, i - 1, mod);
    }
    cout << ans % mod << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define rep(i, b) FOR(i, 0, b)
#define INF mugen
#define dump(x) cerr << #x << "=" << x << endl
#define ALL(a) (a).begin(), (a).end()
#define EACH(e, v) for (auto &e : v)
#define SORT(v) sort(ALL(v))
#define PERM(v)                                                                \
  SORT(v);                                                                     \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(v)))
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
typedef pair<int, int> P;
template <class T> void chmin(T &a, T const &b) {
  if (b < a)
    a = b;
}
template <class T> void chmax(T &a, T const &b) {
  if (b > a)
    a = b;
}
template <typename T> string to_string(const T &n) {
  ostringstream stm;
  stm << n;
  return stm.str();
}
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
using ll = long long;
const ll mod = 1000'000'007;
#define int long long
ll mod_pow(ll a, ll b, ll r) {
  return b <= 0 ? 1 : (b % 2 ? a : 1) * mod_pow(a * a % r, b / 2, r) % r;
}

vector<ll> fac(1123456);  // n!(mod M)
vector<ll> ifac(1123456); // k!^{M-2} (mod M)

ll comb(ll a, ll b, ll M) { // aCbをmod計算
  if (a == 0 && b == 0)
    return 1;
  if (a < b || a < 0)
    return 0;
  ll tmp = ifac[a - b] * ifac[b] % M;
  return tmp * fac[a] % M;
}

ll dupc(ll a, ll b, ll M) {
  if (a == 0 && b == 0)
    return 1;
  if (a < 0 || b == 0)
    return 0;
  ll tmp = ifac[a - 1] * ifac[b] % M;
  return tmp * fac[a + b - 1] % M;
}
vector<vector<ll>> cmemo;
ll combbi(int n, int k, int MOD) {
  if (k == 0 || n == k)
    return cmemo[n][k] = 1;
  if (cmemo[n][k])
    return cmemo[n][k];
  if (n < k)
    return 0;
  return cmemo[n][k] =
             ((combbi(n - 1, k - 1, MOD) + combbi(n - 1, k, MOD)) % MOD);
}
signed main() {
  ll n, k, ans = 0LL;
  cin >> n >> k;

  fac[0] = 1;
  ifac[0] = 1;
  for (ll i = 0; i < 112345; i++) {
    fac[i + 1] = fac[i] * (i + 1) % mod;                  // n!(mod M)
    ifac[i + 1] = ifac[i] * mod_pow(i + 1, mod - 2, mod); // k!^{M-2} (mod M)
  }
  cmemo.assign(n + 1, vector<ll>(n + 1, 0));

  // dump(comb(4,2,mod));

  for (int i = 1; i <= k; i++) {
    ans = 0LL;
    {
      int bres = k - i;
      int rres = n - k - (i - 1);

      ans += combbi(rres + i, i, mod) % mod;
      ans *= combbi(bres + i - 1, i - 1, mod);
    }
    cout << ans % mod << endl;
  }
}