Problem p03270 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
// 217
// 44

using namespace std;

const int MOD = 998244353;
const int MAXN = 2000;

inline void mod(int &x) {
  if (x >= MOD)
    x -= MOD;
}

int comb[MAXN + 1][MAXN + 1];
int p2[MAXN + 1];

inline int get(int n, int k) {
  if (n < 0 || k <= 0)
    return 0;
  return comb[n + k - 1][k - 1];
}

int main() {
  // ifstream cin("A.in");
  // ofstream cout("A.out");
  int n, k, i, j;
  ios::sync_with_stdio(false);
  cin >> k >> n;
  for (i = 0; i <= MAXN; i++) {
    comb[i][0] = 1;
    for (j = 1; j <= i; j++) {
      comb[i][j] = comb[i - 1][j] + comb[i - 1][j - 1];
      mod(comb[i][j]);
    }
  }
  p2[0] = 1;
  for (i = 1; i <= MAXN; i++) {
    p2[i] = p2[i - 1] * 2;
    mod(p2[i]);
  }
  for (int val = 2; val <= 2 * k; val++) {
    int m = val / 2 - max(1, val - k) + 1;
    int ans = 0;
    if (val & 1) {
      for (i = 0; i <= m; i++) {
        int cur = (1LL * comb[m][i] * p2[i]) % MOD;
        cur = (1LL * cur * get(n - i, i + k - 2 * m)) % MOD;
        ans += cur;
        mod(ans);
      }
    } else {
      for (i = 0; i < m; i++) {
        int cur = (1LL * comb[m - 1][i] * p2[i]) % MOD;
        cur = (1LL * cur * get(n - i, i + k - 2 * m + 1)) % MOD;
        ans += cur;
        mod(ans);
      }
      for (i = 1; i <= m; i++) {
        int cur = (1LL * comb[m - 1][i - 1] * p2[i - 1]) % MOD;
        cur = (1LL * cur * get(n - i, i + k - 2 * m)) % MOD;
        ans += cur;
        mod(ans);
      }
    }
    cout << ans << "\n";
  }
  // cin.close();
  // cout.close();
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
// 217
// 44

using namespace std;

const int MOD = 998244353;
const int MAXN = 4000;

inline void mod(int &x) {
  if (x >= MOD)
    x -= MOD;
}

int comb[MAXN + 1][MAXN + 1];
int p2[MAXN + 1];

inline int get(int n, int k) {
  if (n < 0 || k <= 0)
    return 0;
  return comb[n + k - 1][k - 1];
}

int main() {
  // ifstream cin("A.in");
  // ofstream cout("A.out");
  int n, k, i, j;
  ios::sync_with_stdio(false);
  cin >> k >> n;
  for (i = 0; i <= MAXN; i++) {
    comb[i][0] = 1;
    for (j = 1; j <= i; j++) {
      comb[i][j] = comb[i - 1][j] + comb[i - 1][j - 1];
      mod(comb[i][j]);
    }
  }
  p2[0] = 1;
  for (i = 1; i <= MAXN; i++) {
    p2[i] = p2[i - 1] * 2;
    mod(p2[i]);
  }
  for (int val = 2; val <= 2 * k; val++) {
    int m = val / 2 - max(1, val - k) + 1;
    int ans = 0;
    if (val & 1) {
      for (i = 0; i <= m; i++) {
        int cur = (1LL * comb[m][i] * p2[i]) % MOD;
        cur = (1LL * cur * get(n - i, i + k - 2 * m)) % MOD;
        ans += cur;
        mod(ans);
      }
    } else {
      for (i = 0; i < m; i++) {
        int cur = (1LL * comb[m - 1][i] * p2[i]) % MOD;
        cur = (1LL * cur * get(n - i, i + k - 2 * m + 1)) % MOD;
        ans += cur;
        mod(ans);
      }
      for (i = 1; i <= m; i++) {
        int cur = (1LL * comb[m - 1][i - 1] * p2[i - 1]) % MOD;
        cur = (1LL * cur * get(n - i, i + k - 2 * m)) % MOD;
        ans += cur;
        mod(ans);
      }
    }
    cout << ans << "\n";
  }
  // cin.close();
  // cout.close();
  return 0;
}