Problem p03270 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define szz(x) ((int)(x).size())
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef unsigned int uint;
typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<db, db> pdd;

int IT_MAX = 1 << 19;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

const int MX = 5005;
const int MM = 998244353;

int C[MX][MX];

ll H(ll n, ll k) { return n + k - 1 < 0 ? 0 : C[n + k - 1][k]; }

int N, K;
ll solve(int n, int k, int K) {
  ll ans = 0;
  for (int i = 0; i <= k; i++) {
    ll v = H(K, n - 2 * i) * C[k][i] % MM;
    if (i % 2 == 0)
      ans = (ans + v) % MM;
    else
      ans = (ans + MM - v) % MM;
  }
  return ans;
}

int main() {
  C[0][0] = 1;
  for (int i = 1; i < MX; i++) {
    C[i][0] = 1;
    for (int j = 1; j <= i; j++)
      C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % MM;
  }
  scanf("%d%d", &K, &N);
  if (K == 1)
    return !printf("0\n");
  for (int k = 2; k <= 2 * K; k++) {
    ll ans = 0;
    int v = min((k - 1) / 2, (2 * K - k + 1) / 2);
    if (k % 2 == 0)
      ans = (solve(N - 1, v, K - 1) + solve(N, v, K - 1)) % MM;
    else
      ans = solve(N, v, K);
    printf("%lld\n", ans);
  }
}


Fixed submission:
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define szz(x) ((int)(x).size())
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef unsigned int uint;
typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<db, db> pdd;

int IT_MAX = 1 << 19;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

const int MX = 5005;
const int MM = 998244353;

int C[MX][MX];

ll H(ll n, ll k) { return n + k - 1 < 0 || k < 0 ? 0 : C[n + k - 1][k]; }

int N, K;
ll solve(int n, int k, int K) {
  ll ans = 0;
  for (int i = 0; i <= k; i++) {
    ll v = H(K, n - 2 * i) * C[k][i] % MM;
    if (i % 2 == 0)
      ans = (ans + v) % MM;
    else
      ans = (ans + MM - v) % MM;
  }
  return ans;
}

int main() {
  C[0][0] = 1;
  for (int i = 1; i < MX; i++) {
    C[i][0] = 1;
    for (int j = 1; j <= i; j++)
      C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % MM;
  }
  scanf("%d%d", &K, &N);
  if (K == 1)
    return !printf("0\n");
  for (int k = 2; k <= 2 * K; k++) {
    ll ans = 0;
    int v = min((k - 1) / 2, (2 * K - k + 1) / 2);
    if (k % 2 == 0)
      ans = (solve(N - 1, v, K - 1) + solve(N, v, K - 1)) % MM;
    else
      ans = solve(N, v, K);
    printf("%lld\n", ans);
  }
}