Problem p03332 (C++)

Buggy submission (status: Runtime Error):
/*+lmake
 * STD = c++14
 * DEFINE += WAAUTOMATON
 */
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
#ifdef WAAUTOMATON
#define debug(args...)                                                         \
  {                                                                            \
    dbg, args;                                                                 \
    cerr << endl;                                                              \
  }
#else
#define debug(args...) // Just strip off all debug tokens
#endif

struct debugger {
  template <typename T> debugger &operator,(const T &v) {
    cerr << v << " ";
    return *this;
  }
} dbg;

#define MAXN 300000
#define kcz 998244353
LL f[MAXN + 10];
LL qpow(LL x, LL n = kcz - 2) {
  if (n == 1)
    return x;
  LL t = qpow(x, n / 2);
  t = t * t % kcz;
  if (n % 2 == 1)
    t = t * x % kcz;
  return t;
}
LL calcC(LL n, LL k) { return f[n] * qpow(f[k]) % kcz * qpow(f[n - k]) % kcz; }
void solve(long long N, long long A, long long B, long long K) {
  f[0] = 1;
  for (int i = 1; i <= N; ++i) {
    f[i] = f[i - 1] * i % kcz;
  }
  LL ans = 0;
  for (int a = 0; a <= N; ++a) {
    LL t = K - a * A;
    if (t % B != 0)
      continue;
    LL b = t / B;
    ans += calcC(N, a) * calcC(N, b);
    ans %= kcz;
  }
  cout << ans << endl;
}

int main() {
#ifdef WAAUTOMATON
  // freopen("in.txt","r",stdin);
#endif
  long long K;
  long long A;
  long long N;
  long long B;
  scanf("%lld", &N);
  scanf("%lld", &A);
  scanf("%lld", &B);
  scanf("%lld", &K);
  solve(N, A, B, K);
  return 0;
}


Fixed submission:
/*+lmake
 * STD = c++14
 * DEFINE += WAAUTOMATON
 */
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
#ifdef WAAUTOMATON
#define debug(args...)                                                         \
  {                                                                            \
    dbg, args;                                                                 \
    cerr << endl;                                                              \
  }
#else
#define debug(args...) // Just strip off all debug tokens
#endif

struct debugger {
  template <typename T> debugger &operator,(const T &v) {
    cerr << v << " ";
    return *this;
  }
} dbg;

#define MAXN 300000
#define kcz 998244353
LL f[MAXN + 10];
LL qpow(LL x, LL n = kcz - 2) {
  if (n == 1)
    return x;
  LL t = qpow(x, n / 2);
  t = t * t % kcz;
  if (n % 2 == 1)
    t = t * x % kcz;
  return t;
}
LL calcC(LL n, LL k) { return f[n] * qpow(f[k]) % kcz * qpow(f[n - k]) % kcz; }
void solve(long long N, long long A, long long B, long long K) {
  f[0] = 1;
  for (int i = 1; i <= N; ++i) {
    f[i] = f[i - 1] * i % kcz;
  }
  LL ans = 0;
  for (int a = 0; a <= N; ++a) {
    LL t = K - a * A;
    if (t % B != 0)
      continue;
    LL b = t / B;
    if (b < 0 || b > N)
      continue;
    ans += calcC(N, a) * calcC(N, b);
    ans %= kcz;
  }
  cout << ans << endl;
}

int main() {
#ifdef WAAUTOMATON
  // freopen("in.txt","r",stdin);
#endif
  long long K;
  long long A;
  long long N;
  long long B;
  scanf("%lld", &N);
  scanf("%lld", &A);
  scanf("%lld", &B);
  scanf("%lld", &K);
  solve(N, A, B, K);
  return 0;
}