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

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

#pragma region // {{{

#define all(x) std::begin(x), std::end(x)
#define rall(x) std::rbegin(x), std::rend(x)
#define rep(i, begin, end)                                                     \\
  for (int64_t i{begin}, i##_end{end}; i < i##_end; ++i)
#define repc(i, begin, last)                                                   \\
  for (int64_t i{begin}, i##_last{last}; i <= i##_last; ++i)
#define repr(i, begin, last)                                                   \\
  for (int64_t i{begin}, i##_last{last}; i >= i##_last; --i)
#define let const auto
using i64 = std::int64_t;
using u64 = std::uint64_t;

constexpr int32_t INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;

void ioSetup() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(11);
  std::cerr << std::fixed << std::setprecision(11);
  std::clog << std::fixed << std::setprecision(11);
}

template <class T> std::istream &operator,(std::istream &is, T &rhs) {
  return is >> rhs;
}

#define var(type, ...)                                                         \\
  type __VA_ARGS__;                                                            \\
  std::cin >> __VA_ARGS__

inline void println() { std::cout << '\\n'; }
template <class Head, class... Tail>
inline void println(Head &&head, Tail &&...tail) {
  std::cout << head << " " + (!sizeof...(tail));
  println(std::forward<Tail>(tail)...);
}

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

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

#pragma endregion // }}}

constexpr int MOD = int(1e9) + 7;
// constexpr int MOD = 998244353;

i64 S;

i64 dp(int i, int sum) {
  if (sum == S)
    return 1;
  if (sum > S)
    return 0;

  i64 ret = 0;
  repc(a, 3, S - sum) { ret += dp(i + 1, int(sum + a)); }

  return ret;
}

signed main() {
  ioSetup();

  cin >> S;
  if (S == 1) {
    println(0);
    return 0;
  }

  vector<vector<i64>> dp(S, vector<i64>(S + 5, 0));
  rep(i, 0, S) { dp[i][S] = 1; }

  repr(i, S / 3, 0) {
    repr(j, S - 1, 0) { (dp[i + 1][j] += dp[i + 1][j + 1]) %= MOD; }
    rep(j, 0, S) { dp[i][j] = dp[i + 1][j + 3]; }
  }
  println(dp[0][0]);

  return 0;
}


Error: 0

Fixed submission:

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

#pragma region // {{{

#define all(x) std::begin(x), std::end(x)
#define rall(x) std::rbegin(x), std::rend(x)
#define rep(i, begin, end)                                                     \\
  for (int64_t i{begin}, i##_end{end}; i < i##_end; ++i)
#define repc(i, begin, last)                                                   \\
  for (int64_t i{begin}, i##_last{last}; i <= i##_last; ++i)
#define repr(i, begin, last)                                                   \\
  for (int64_t i{begin}, i##_last{last}; i >= i##_last; --i)
#define let const auto
using i64 = std::int64_t;
using u64 = std::uint64_t;

constexpr int32_t INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;

void ioSetup() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(11);
  std::cerr << std::fixed << std::setprecision(11);
  std::clog << std::fixed << std::setprecision(11);
}

template <class T> std::istream &operator,(std::istream &is, T &rhs) {
  return is >> rhs;
}

#define var(type, ...)                                                         \\
  type __VA_ARGS__;                                                            \\
  std::cin >> __VA_ARGS__

inline void println() { std::cout << '\\n'; }
template <class Head, class... Tail>
inline void println(Head &&head, Tail &&...tail) {
  std::cout << head << " " + (!sizeof...(tail));
  println(std::forward<Tail>(tail)...);
}

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

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

#pragma endregion // }}}

constexpr int MOD = int(1e9) + 7;
// constexpr int MOD = 998244353;

i64 S;

i64 dp(int i, int sum) {
  if (sum == S)
    return 1;
  if (sum > S)
    return 0;

  i64 ret = 0;
  repc(a, 3, S - sum) { ret += dp(i + 1, int(sum + a)); }

  return ret;
}

signed main() {
  ioSetup();

  cin >> S;
  /* println(dp(0, 0)); */

  vector<vector<i64>> dp(S, vector<i64>(S + 5, 0));
  rep(i, 0, S) { dp[i][S] = 1; }

  repr(i, S / 3, 0) {
    repr(j, S - 1, 0) { (dp[i + 1][j] += dp[i + 1][j + 1]) %= MOD; }
    rep(j, 0, S) { dp[i][j] = dp[i + 1][j + 3]; }
  }
  println(dp[0][0]);

  return 0;
}