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

#include <bits/stdc++.h>
using namespace std;

#if 1 // 折り畳み用
//------------------------------------------------------------
using ll = long long;
#define int ll

#define FOR(i, s, e) for (ll i = ll(s); i < (ll)e; ++i)
#define RFOR(i, s, e) for (ll i = ll(e) - 1; i >= ll(s); --i)
#define REP(i, n) for (ll i = 0, i##_size = n; i < i##_size; ++i)
#define RREP(i, n) for (ll i = ll(n) - 1; i >= 0; --i)

//------------------------------------------------------------
template <class T> struct arr : public vector<T> {
  arr() {}
  arr(ll n, T v = T()) : vector<T>(n, v) {}
  void init(ll n, T v = T()) {
    this->clear();
    this->resize(n, v);
  }
  ll sz() const { return (ll)this->size(); }
  void pb(T v) { this->push_back(v); }
  void sort() { std::sort(this->begin(), this->end()); }
  void rsort() { std::sort(this->begin(), this->end(), greater<T>()); }
};
using ints = arr<ll>;
using intss = arr<arr<ll>>;

template <class T> struct que : public queue<T> {
  ll sz() const { return (ll)this->size(); }
  T popfront() {
    T v = this->front();
    this->pop();
    return v;
  }
};

//------------------------------------------------------------
#if defined(TEST)
extern istream &myInputStream;
extern ostream &myOutputStream;
#else
istream &myInputStream = cin;
ostream &myOutputStream = cout;
#endif
struct input_ar {
  ll n;
  input_ar(ll n_) : n(n_) {}
  template <class T> operator arr<T>() {
    arr<T> var(n);
    REP(i, n) { myInputStream >> var[i]; };
    return var;
  }
};

struct input {
  template <class T> operator T() {
    T var;
    myInputStream >> var;
    return var;
  }
  input_ar operator()(ll N) { return input_ar(N); }
} input;

template <class T> void output(T var) { myOutputStream << (var) << '\\n'; }

//------------------------------------------------------------
template <class T> void chmin(T &a, T b) {
  if (b < a) {
    a = b;
  }
}
template <class T> void chmax(T &a, T b) {
  if (b > a) {
    a = b;
  }
}

struct bfs {
  ints froms;
  ints steps;

  bfs(int N, intss const &adjacency) {
    froms.init(N, -1);
    steps.init(N, -1);

    que<ll> queue;
    queue.push(0);
    froms[0] = 0;
    steps[0] = 0;

    while (queue.empty() == false) {
      ll p = queue.popfront();

      for (ll n : adjacency[p]) {
        if (froms[n] != -1) {
          continue;
        }

        froms[n] = p;
        steps[n] = steps[p] + 1;
        queue.push(n);
      }
    }
  }
};

//------------------------------------------------------------
#if !defined(TEST)
void myMain();
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(16);
  myMain();
  return 0;
}
#endif

#endif

#define DIV 998244353

int N;
int S;
ints A;

int dp[3001][3001];
int Calc(int index, int sum) {
  if (index == N) {
    if (sum == S) {
      return 1;
    } else {
      return 0;
    }
  }
  if (sum > S) {
    return 0;
  }

  if (dp[index][sum] >= 0) {
    return dp[index][sum];
  }

  int c1 = Calc(index + 1, sum + A[index]);
  int c2 = Calc(index + 1, sum);
  int c3 = c2;

  int r = (c1 + c2 + c3) % DIV;

  dp[index][sum] = r;

  return r;
}

//------------------------------------------------------------
void myMain() {
  N = input;
  S = input;
  A = input(N);
  A.sort();

  REP(i, N + 1) {
    REP(j, S + 1) { dp[i][j] = -1; }
  }

  int ans = Calc(0, 0);
  output(ans);
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

#if 1 // 折り畳み用
//------------------------------------------------------------
using ll = long long;
#define int ll

#define FOR(i, s, e) for (ll i = ll(s); i < (ll)e; ++i)
#define RFOR(i, s, e) for (ll i = ll(e) - 1; i >= ll(s); --i)
#define REP(i, n) for (ll i = 0, i##_size = n; i < i##_size; ++i)
#define RREP(i, n) for (ll i = ll(n) - 1; i >= 0; --i)

//------------------------------------------------------------
template <class T> struct arr : public vector<T> {
  arr() {}
  arr(ll n, T v = T()) : vector<T>(n, v) {}
  void init(ll n, T v = T()) {
    this->clear();
    this->resize(n, v);
  }
  ll sz() const { return (ll)this->size(); }
  void pb(T v) { this->push_back(v); }
  void sort() { std::sort(this->begin(), this->end()); }
  void rsort() { std::sort(this->begin(), this->end(), greater<T>()); }
};
using ints = arr<ll>;
using intss = arr<arr<ll>>;

template <class T> struct que : public queue<T> {
  ll sz() const { return (ll)this->size(); }
  T popfront() {
    T v = this->front();
    this->pop();
    return v;
  }
};

//------------------------------------------------------------
#if defined(TEST)
extern istream &myInputStream;
extern ostream &myOutputStream;
#else
istream &myInputStream = cin;
ostream &myOutputStream = cout;
#endif
struct input_ar {
  ll n;
  input_ar(ll n_) : n(n_) {}
  template <class T> operator arr<T>() {
    arr<T> var(n);
    REP(i, n) { myInputStream >> var[i]; };
    return var;
  }
};

struct input {
  template <class T> operator T() {
    T var;
    myInputStream >> var;
    return var;
  }
  input_ar operator()(ll N) { return input_ar(N); }
} input;

template <class T> void output(T var) { myOutputStream << (var) << '\\n'; }

//------------------------------------------------------------
template <class T> void chmin(T &a, T b) {
  if (b < a) {
    a = b;
  }
}
template <class T> void chmax(T &a, T b) {
  if (b > a) {
    a = b;
  }
}

struct bfs {
  ints froms;
  ints steps;

  bfs(int N, intss const &adjacency) {
    froms.init(N, -1);
    steps.init(N, -1);

    que<ll> queue;
    queue.push(0);
    froms[0] = 0;
    steps[0] = 0;

    while (queue.empty() == false) {
      ll p = queue.popfront();

      for (ll n : adjacency[p]) {
        if (froms[n] != -1) {
          continue;
        }

        froms[n] = p;
        steps[n] = steps[p] + 1;
        queue.push(n);
      }
    }
  }
};

//------------------------------------------------------------
#if !defined(TEST)
void myMain();
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(16);
  myMain();
  return 0;
}
#endif

#endif

#define DIV 998244353

int N;
int S;
ints A;

int dp[3001][3001];
int Calc(int index, int sum) {
  if (index == N) {
    if (sum == S) {
      return 1;
    } else {
      return 0;
    }
  }

  if (dp[index][sum] >= 0) {
    return dp[index][sum];
  }

  int c1 = Calc(index + 1, sum + A[index]);
  int c2 = Calc(index + 1, sum);
  int c3 = c2;

  int r = (c1 + c2 + c3) % DIV;

  dp[index][sum] = r;

  return r;
}

//------------------------------------------------------------
void myMain() {
  N = input;
  S = input;
  A = input(N);
  A.sort();

  REP(i, N + 1) {
    REP(j, S + 1) { dp[i][j] = -1; }
  }

  int ans = Calc(0, 0);
  output(ans);
}