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

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i, a, b) for (ll i = (a), _b = (b); i <= _b; i++)
#define frr(i, a, b) for (ll i = (a), _b = (b); i >= _b; i--)
#define rep(i, n) for (ll i = 0, _n = (n); i < _n; i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define debug(x) cout << #x << ": " << x << endl
#define all(ar) ar.begin(), ar.end()
#define rall(ar) ar.rbegin(), ar.rend()
#define sz(x) ((long long)x.size())
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
#define mp make_pair
#define ff first
#define ss second
#define MOD 1000000007

auto clk = clock();
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll INF = 1e18L + 5;
const int d4i[4] = {-1, 0, 1, 0}, d4j[4] = {0, 1, 0, -1};
const int d8i[8] = {-1, -1, 0, 1, 1, 1, 0, -1},
          d8j[8] = {0, 1, 1, 1, 0, -1, -1, -1};

typedef pair<ll, ll> ii;
typedef pair<ll, ii> iii;
typedef vector<ii> vii;
typedef vector<ll> vi;
typedef vector<int> vint;
typedef vector<string> vs;
typedef vector<vi> vvi;

const int N_MAX = 2005;
ll dp[N_MAX][N_MAX];

ll combi(ll n, ll r) {
  if (r == 0 || r == n)
    return 1;
  if (dp[n][r] != -1)
    return dp[n][r];
  ll a = combi(n - 1, r - 1);
  ll b = combi(n - 1, r);
  dp[n][r] = (a + b) % MOD;
  return dp[n][r];
}

ll modexp(ll base, ll power) {
  if (base == 0)
    return 0ll;
  if (power == 0)
    return 1ll;
  ll res = 1;
  while (power) {
    if (power & 1)
      res = (res * base) % MOD;
    base = (base * base) % MOD;
    power /= 2;
  }
  return res;
}

void solve() {
  ll n;
  cin >> n;
  ll dp[n + 1];
  dp[0] = 0;
  dp[1] = 0;
  dp[2] = 0;
  fr(i, 3, n) dp[i] = 1;
  fr(i, 4, n) {
    for (ll j = 3; j <= i - 3; j++) {
      dp[i] = (dp[i] + dp[j]) % MOD;
    }
  }
  cout << dp[n];
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout << setprecision(11);
  memset(dp, -1, sizeof(dp));
  ll t = 1;
  // cin>>t;
  while (t--)
    solve();

  // cout<<endl<<endl<<"Time elapsed:
  // "<<((double)(clock()-clk)/CLOCKS_PER_SEC)*1000<<"ms"<<endl;
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i, a, b) for (ll i = (a), _b = (b); i <= _b; i++)
#define frr(i, a, b) for (ll i = (a), _b = (b); i >= _b; i--)
#define rep(i, n) for (ll i = 0, _n = (n); i < _n; i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define debug(x) cout << #x << ": " << x << endl
#define all(ar) ar.begin(), ar.end()
#define rall(ar) ar.rbegin(), ar.rend()
#define sz(x) ((long long)x.size())
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
#define mp make_pair
#define ff first
#define ss second
#define MOD 1000000007

auto clk = clock();
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll INF = 1e18L + 5;
const int d4i[4] = {-1, 0, 1, 0}, d4j[4] = {0, 1, 0, -1};
const int d8i[8] = {-1, -1, 0, 1, 1, 1, 0, -1},
          d8j[8] = {0, 1, 1, 1, 0, -1, -1, -1};

typedef pair<ll, ll> ii;
typedef pair<ll, ii> iii;
typedef vector<ii> vii;
typedef vector<ll> vi;
typedef vector<int> vint;
typedef vector<string> vs;
typedef vector<vi> vvi;

const int N_MAX = 2005;
ll dp[N_MAX][N_MAX];

ll combi(ll n, ll r) {
  if (r == 0 || r == n)
    return 1;
  if (dp[n][r] != -1)
    return dp[n][r];
  ll a = combi(n - 1, r - 1);
  ll b = combi(n - 1, r);
  dp[n][r] = (a + b) % MOD;
  return dp[n][r];
}

ll modexp(ll base, ll power) {
  if (base == 0)
    return 0ll;
  if (power == 0)
    return 1ll;
  ll res = 1;
  while (power) {
    if (power & 1)
      res = (res * base) % MOD;
    base = (base * base) % MOD;
    power /= 2;
  }
  return res;
}

void solve() {
  ll n;
  cin >> n;
  ll dp[n + 1];
  fr(i, 3, n) dp[i] = 1;
  dp[3] = 1;
  fr(i, 4, n) {
    for (ll j = 3; j <= i - 3; j++) {
      dp[i] = (dp[i] + dp[j]) % MOD;
    }
  }
  cout << dp[n];
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout << setprecision(11);
  memset(dp, -1, sizeof(dp));
  ll t = 1;
  // cin>>t;
  while (t--)
    solve();

  // cout<<endl<<endl<<"Time elapsed:
  // "<<((double)(clock()-clk)/CLOCKS_PER_SEC)*1000<<"ms"<<endl;
  return 0;
}