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

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string.h>
#include <string>
#include <unistd.h>
#include <unordered_map>
#include <vector>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vvvl> vvvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef vector<long double> vld;
typedef vector<vld> vvld;
typedef unordered_map<ll, ll> uii;
typedef unordered_map<ll, ll> uuii;
typedef unordered_map<ll, ll> uuuii;
typedef pair<ll, ll> PL;
typedef vector<PL> vpl;
typedef vector<vector<PL>> vvpl;
typedef vector<vvpl> vvvpl;
typedef pair<ll, PL> TL;
typedef vector<TL> vtl;
typedef vector<vtl> vvtl;
typedef bitset<64> bs;
const ll LINF = 1e18;
const long double pi = 3.1415926535897932;
const string endstr = "\\n";
#define FOR(i, a, b) for (ll i = (a); i < b; i++)
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FORMAP(it, m) for (auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define ALL(X) (X).begin(), (X).end()

template <typename T> T gcd(T a, T b) { return (a == 0) ? b : gcd(b % a, a); }
template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

bool p_comp_fs(const PL p1, const PL p2) { return p1.first < p2.first; };
bool p_comp_fg(const PL p1, const PL p2) { return p1.first > p2.first; };
bool p_comp_ss(const PL p1, const PL p2) { return p1.second < p2.second; };
bool p_comp_sg(const PL p1, const PL p2) { return p1.second > p2.second; };
template <typename T> vector<T> uniquen(vector<T> vec /* copy */) {
  sort(ALL(vec));
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  return vec;
}

inline ll popcnt(ll x) { return __builtin_popcountll((unsigned long long)x); };
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
// friend bool operator<(const tpl& lhs, const tpl& rhs){
//     return std::tie(lhs.l, lhs.r) < std::tie(rhs.l, rhs.r);
// }

bool bit(ll st, ll b) { return ((st >> b) & 1) == 1; }

const ll mod = 998244353;
template <int mod> struct ModInt {
  int x;
  ModInt() : x(0) {}
  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
  ModInt &operator+=(const ModInt &p) {
    if ((x += p.x) >= mod)
      x -= mod;
    return *this;
  }
  ModInt &operator-=(const ModInt &p) {
    if ((x += mod - p.x) >= mod)
      x -= mod;
    return *this;
  }
  ModInt &operator*=(const ModInt &p) {
    x = (int)(1LL * x * p.x % mod);
    return *this;
  }
  ModInt &operator/=(const ModInt &p) {
    *this *= p.inv();
    return *this;
  }
  ModInt operator-() const { return ModInt(-x); }
  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
  bool operator==(const ModInt &p) const { return x == p.x; }
  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inv() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while (b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while (n > 0) {
      if (n & 1)
        ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; }

  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt<mod>(t);
    return (is);
  }

  static int get_mod() { return mod; }
};

using mint = ModInt<mod>;
typedef vector<mint> vm;
typedef vector<vm> vvm;
typedef vector<vvm> vvvm;

typedef unordered_map<ll, mint> uim;
typedef unordered_map<ll, uim> uuim;
typedef unordered_map<ll, uuim> uuuim;

int main() {
#ifdef __DEBUG_LOCAL__
  ifstream file("../../../../../in.txt");
  if (file.is_open())
    cin.rdbuf(file.rdbuf());
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  ll N, S;
  cin >> N >> S;
  vl A(N);
  rep(i, N) cin >> A[i];

  vvm dp(N + 1, vm(3000 + 10, 0));

  rep(i, N) {
    rep(k, S + 1) {
      if (k == 0) {
        dp[i + 1][k + A[i]] += mint(2).pow(i);
      } else if (k + A[i] < S + 1) {
        dp[i + 1][k + A[i]] += dp[i][k];
      }

      dp[i + 1][k] += mint(2) * dp[i][k];
    }
  }

  cout << dp[N][S] << endstr;
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string.h>
#include <string>
#include <unistd.h>
#include <unordered_map>
#include <vector>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vvvl> vvvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef vector<long double> vld;
typedef vector<vld> vvld;
typedef unordered_map<ll, ll> uii;
typedef unordered_map<ll, ll> uuii;
typedef unordered_map<ll, ll> uuuii;
typedef pair<ll, ll> PL;
typedef vector<PL> vpl;
typedef vector<vector<PL>> vvpl;
typedef vector<vvpl> vvvpl;
typedef pair<ll, PL> TL;
typedef vector<TL> vtl;
typedef vector<vtl> vvtl;
typedef bitset<64> bs;
const ll LINF = 1e18;
const long double pi = 3.1415926535897932;
const string endstr = "\\n";
#define FOR(i, a, b) for (ll i = (a); i < b; i++)
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FORMAP(it, m) for (auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define ALL(X) (X).begin(), (X).end()

template <typename T> T gcd(T a, T b) { return (a == 0) ? b : gcd(b % a, a); }
template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

bool p_comp_fs(const PL p1, const PL p2) { return p1.first < p2.first; };
bool p_comp_fg(const PL p1, const PL p2) { return p1.first > p2.first; };
bool p_comp_ss(const PL p1, const PL p2) { return p1.second < p2.second; };
bool p_comp_sg(const PL p1, const PL p2) { return p1.second > p2.second; };
template <typename T> vector<T> uniquen(vector<T> vec /* copy */) {
  sort(ALL(vec));
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  return vec;
}

inline ll popcnt(ll x) { return __builtin_popcountll((unsigned long long)x); };
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
// friend bool operator<(const tpl& lhs, const tpl& rhs){
//     return std::tie(lhs.l, lhs.r) < std::tie(rhs.l, rhs.r);
// }

bool bit(ll st, ll b) { return ((st >> b) & 1) == 1; }

const ll mod = 998244353;
template <int mod> struct ModInt {
  int x;
  ModInt() : x(0) {}
  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
  ModInt &operator+=(const ModInt &p) {
    if ((x += p.x) >= mod)
      x -= mod;
    return *this;
  }
  ModInt &operator-=(const ModInt &p) {
    if ((x += mod - p.x) >= mod)
      x -= mod;
    return *this;
  }
  ModInt &operator*=(const ModInt &p) {
    x = (int)(1LL * x * p.x % mod);
    return *this;
  }
  ModInt &operator/=(const ModInt &p) {
    *this *= p.inv();
    return *this;
  }
  ModInt operator-() const { return ModInt(-x); }
  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
  bool operator==(const ModInt &p) const { return x == p.x; }
  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inv() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while (b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while (n > 0) {
      if (n & 1)
        ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; }

  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt<mod>(t);
    return (is);
  }

  static int get_mod() { return mod; }
};

using mint = ModInt<mod>;
typedef vector<mint> vm;
typedef vector<vm> vvm;
typedef vector<vvm> vvvm;

typedef unordered_map<ll, mint> uim;
typedef unordered_map<ll, uim> uuim;
typedef unordered_map<ll, uuim> uuuim;

int main() {
#ifdef __DEBUG_LOCAL__
  ifstream file("../../../../../in.txt");
  if (file.is_open())
    cin.rdbuf(file.rdbuf());
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  ll N, S;
  cin >> N >> S;
  vl A(N);
  rep(i, N) cin >> A[i];

  vvm dp(N + 1, vm(S + 10, 0));

  rep(i, N) {
    rep(k, S + 1) {
      if (k == 0) {
        dp[i + 1][k + A[i]] += mint(2).pow(i);
      } else if (k + A[i] < S + 1) {
        dp[i + 1][k + A[i]] += dp[i][k];
      }

      dp[i + 1][k] += mint(2) * dp[i][k];
    }
  }

  cout << dp[N][S] << endstr;
  return 0;
}