Problem p02662 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

const ll MOD = 998244353;
const int INF = 1 << 30;
// const ll INF = (ll)1e18 + 1;

const int MAX = 510000; // nCrのr
// const ll INF = (ll)1e18 + 1;

#include <cassert>
long long fac[MAX], finv[MAX], inv[MAX], facn[MAX];
class mint {
public:
  long long x;
  mint(long long x = 0) : x((x % MOD + MOD) % MOD) {}
  // mint operator-() const{ return mint(-x);}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint &a) {
    if ((x += a.x) >= MOD)
      x -= MOD;
    return *this;
  }
  mint &operator-=(const mint &a) {
    if ((x += MOD - a.x) >= MOD)
      x -= MOD;
    return *this;
  }
  mint &operator*=(const mint &a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator+(const mint &a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint &a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint &a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const { return pow(MOD - 2); }
  mint &operator/=(const mint &a) { return (*this) *= a.inv(); }
  mint operator/(const mint &a) const {
    mint res(*this);
    return res /= a;
  }
};

int main() {
  int N, S;
  cin >> N >> S;
  vector<int> a(N);
  rep(i, N) cin >> a[i];

  vector<vector<mint>> dp(N + 1, vector<mint>(S + 1));
  dp[0][0] = 1;
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j <= S; ++j) {
      dp[i + 1][j] += dp[i][j] * 2;
      if (j + a[i] <= S)
        dp[i + 1][j + a[i]] += dp[i][j];
    }
  }
  cout << dp[N][S].x << endl;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

const ll MOD = 998244353;
const int INF = 1 << 30;
// const ll INF = (ll)1e18 + 1;

const int MAX = 510000; // nCrのr
// const ll INF = (ll)1e18 + 1;

#include <cassert>
long long fac[MAX], finv[MAX], inv[MAX], facn[MAX];
class mint {
public:
  long long x;
  mint(long long x = 0) : x((x % MOD + MOD) % MOD) {}
  // mint operator-() const{ return mint(-x);}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint &a) {
    if ((x += a.x) >= MOD)
      x -= MOD;
    return *this;
  }
  mint &operator-=(const mint &a) {
    if ((x += MOD - a.x) >= MOD)
      x -= MOD;
    return *this;
  }
  mint &operator*=(const mint &a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator+(const mint &a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint &a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint &a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const { return pow(MOD - 2); }
  mint &operator/=(const mint &a) { return (*this) *= a.inv(); }
  mint operator/(const mint &a) const {
    mint res(*this);
    return res /= a;
  }
};

template <class T> struct combination {
  vector<T> fact_, ifact_;
  combination(long long n) : fact_(n + 1), ifact_(n + 1) {
    assert(n < MOD);
    fact_[0] = 1;
    for (int i = 1; i <= n; ++i)
      fact_[i] = fact_[i - 1] * i;
    ifact_[n] = fact_[n].inv();
    for (int i = n; i >= 1; --i)
      ifact_[i - 1] = ifact_[i] * i;
  }
  T com(long long n, long long k) {
    if (k < 0 || k > n)
      return 0;
    return fact_[n] * ifact_[k] * ifact_[n - k];
  }
  T fact(ll n) {
    if (n < 0)
      return 0;
    return fact_[n];
  }
};

int main() {
  double N, S;
  cin >> N >> S;
  vector<double> a(N);
  rep(i, N) cin >> a[i];

  combination<mint> C(1000000);
  vector<mint> dp(N + 1, 0); // 全体の答え
  mint ans = 0;
  for (int k = 1; k <= N; ++k) {
    vector<double> tmp = a;
    for (int i = 0; i < N; ++i)
      tmp[i] -= S / k;
    ll cnt = count(tmp.begin(), tmp.end(), 0);
    dp[k] = C.com(cnt, k);
    ans += dp[k];
    for (int i = 1; i < k; ++i) {
      ans += C.com(dp[i].x, i) * C.com(N - i, k - dp[i].x);
    }
  }
  cout << ans.x << endl;
}