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

// skip until line 65
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <istream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define BR "\\n"
#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define ALL(cont) begin(cont), end(cont)
#define AS_MOD(a, b) ((((a) % (b)) + (b)) % (b))
#define MO(a) AS_MOD(a, mod)
#define FEACH(it, cont) for (auto(it) = begin(cont); it != end(cont); ++it)
#define FEACHR(it, cont) for (auto(it) = rbegin(cont); it != rend(cont); ++it)
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define getll()                                                                \\
  ([]() {                                                                      \\
    ll s;                                                                      \\
    scanf("%lld", &s);                                                         \\
    return s;                                                                  \\
  })()
#define getld()                                                                \\
  ([]() {                                                                      \\
    ld s;                                                                      \\
    scanf("%Lf", &s);                                                          \\
    return s;                                                                  \\
  })()
#define prl(P) printf("%lld", P)
#define prd(P) printf("%.10Lf", P)
#define pr(P) printf(P)
#define MAX(V, T) V = max(V, T)
#define MIN(V, T) V = min(V, T)

#define DumpArray(cont, from, to)                                              \\
  for (int __i = from; __i < to; ++__i) {                                      \\
    cout << "(" << __i << ": " << cont[__i] << ")";                            \\
  }                                                                            \\
  cout << endl;

/*
 * ***_bound(6)
 * 5 6 6 6 6 6 7 7 7
 *   ^lower    ^upper
 * void reverse(c.begin(), c.end())
 *
 * graph
 * seg tree
 * dp
 * brute force
 */
struct Comparator {
  int operator()(int l, int r) const { return r < l; }
};
struct Vec;
// set<int, Comparator> S;

// solution below
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
ll table[3010][3010];
ll mod = 998244353;
long long invMod(int n, int p) {
  long long power = n;
  long long res = 1;
  long long index = p - 2;
  for (int i = 0; (index >> i) != 0; ++i) {
    if (((index >> i) & 1) == 1) {
      res = (res * power) % p;
    }
    power = (power * power) % p;
  }
  return res;
}
ll powx(ll n, ll x) {
  long long power = n;
  long long res = 1;
  long long index = x;
  for (int i = 0; (index >> i) != 0; ++i) {
    if (((index >> i) & 1) == 1) {
      res = (res * power) % mod;
    }
    power = (power * power) % mod;
  }
  return res;
}
int main() {
  cout.precision(15);
  cout << fixed;
  ll N, S;
  ll inv2 = invMod(2, mod);
  cin >> N >> S;
  vector<ll> As(N);
  REP(i, N) { cin >> As[i]; }
  memset(table, 0, sizeof(table));
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < 3010; ++j) {
      table[i + 1][j] =
          table[i][j] +
          ((j - As[i] > 0) ? AS_MOD(table[i][j - As[i]] * inv2, mod) : 0);
      table[i + 1][j] = AS_MOD(table[i + 1][j], mod);
      if (j == As[i]) {
        table[i + 1][As[i]] += powx(2, N - 1);
        table[i + 1][As[i]] = AS_MOD(table[i + 1][As[i]], mod);
      }
    }
  }
  cout << table[N][S] << endl;
}


Error: 0

Fixed submission:

// skip until line 65
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <istream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define BR "\\n"
#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define ALL(cont) begin(cont), end(cont)
#define AS_MOD(a, b) ((((a) % (b)) + (b)) % (b))
#define MO(a) AS_MOD(a, mod)
#define FEACH(it, cont) for (auto(it) = begin(cont); it != end(cont); ++it)
#define FEACHR(it, cont) for (auto(it) = rbegin(cont); it != rend(cont); ++it)
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define getll()                                                                \\
  ([]() {                                                                      \\
    ll s;                                                                      \\
    scanf("%lld", &s);                                                         \\
    return s;                                                                  \\
  })()
#define getld()                                                                \\
  ([]() {                                                                      \\
    ld s;                                                                      \\
    scanf("%Lf", &s);                                                          \\
    return s;                                                                  \\
  })()
#define prl(P) printf("%lld", P)
#define prd(P) printf("%.10Lf", P)
#define pr(P) printf(P)
#define MAX(V, T) V = max(V, T)
#define MIN(V, T) V = min(V, T)

#define DumpArray(cont, from, to)                                              \\
  for (int __i = from; __i < to; ++__i) {                                      \\
    cout << "(" << __i << ": " << cont[__i] << ")";                            \\
  }                                                                            \\
  cout << endl;

/*
 * ***_bound(6)
 * 5 6 6 6 6 6 7 7 7
 *   ^lower    ^upper
 * void reverse(c.begin(), c.end())
 *
 * graph
 * seg tree
 * dp
 * brute force
 */
struct Comparator {
  int operator()(int l, int r) const { return r < l; }
};
struct Vec;
// set<int, Comparator> S;

// solution below
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
ll table[1010][1010];
ll mod = 998244353;
long long invMod(int n, int p) {
  long long power = n;
  long long res = 1;
  long long index = p - 2;
  for (int i = 0; (index >> i) != 0; ++i) {
    if (((index >> i) & 1) == 1) {
      res = (res * power) % p;
    }
    power = (power * power) % p;
  }
  return res;
}
ll powx(ll n, ll x) {
  long long power = n;
  long long res = 1;
  long long index = x;
  for (int i = 0; (index >> i) != 0; ++i) {
    if (((index >> i) & 1) == 1) {
      res = (res * power) % mod;
    }
    power = (power * power) % mod;
  }
  return res;
}
int main() {
  cout.precision(15);
  cout << fixed;
  ll N, S;
  ll inv2 = invMod(2, mod);
  cin >> N >> S;
  vector<ll> As(N);
  REP(i, N) { cin >> As[i]; }
  memset(table, 0, sizeof(table));
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < 1010; ++j) {
      table[i + 1][j] =
          table[i][j] +
          ((j - As[i] > 0) ? AS_MOD(table[i][j - As[i]] * inv2, mod) : 0);
      table[i + 1][j] = AS_MOD(table[i + 1][j], mod);
      if (j == As[i]) {
        table[i + 1][As[i]] += powx(2, N - 1);
        table[i + 1][As[i]] = AS_MOD(table[i + 1][As[i]], mod);
      }
    }
  }
  cout << table[N][S] << endl;
}