Problem p03013 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
// #define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL << 60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define RFOR(i, a, b) for (int i = (int)(b - 1); i >= (int)(a); --i)
#define REP(i, n) FOR(i, 0, (n))
#define RREP(i, n) RFOR(i, 0, (n))
#define ITR(itr, mp) for (auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr, mp) for (auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i, a, b) ((a) <= (i) && (i) < (b))
#define debug(x) cout << #x << " = " << (x) << endl;
#define SP << " " <<
typedef pair<int, int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

template <int mod = MOD> class modint {
private:
  int mMOD = mod, mVal;

public:
  constexpr modint(int v = 0) noexcept : mVal(v % mMOD) {
    if (mVal < 0)
      mVal += mMOD;
  }

  constexpr int getMOD() { return mMOD; }

  constexpr modint operator-() const noexcept { return mVal ? mMOD - mVal : 0; }

  constexpr modint operator+(const modint &r) const noexcept {
    return modint(*this) += r;
  }

  constexpr modint operator-(const modint &r) const noexcept {
    return modint(*this) -= r;
  }

  constexpr modint operator*(const modint &r) const noexcept {
    return modint(*this) *= r;
  }

  modint operator/(const modint &r) const noexcept {
    return modint(*this) /= r;
  }

  constexpr modint &operator+=(const modint &r) noexcept {
    mVal += r.mVal;
    if (mVal > mMOD)
      mVal -= mMOD;
    return *this;
  }

  constexpr modint &operator-=(const modint &r) noexcept {
    mVal -= r.mVal;
    if (mVal < 0)
      mVal += mMOD;
    return *this;
  }

  constexpr modint &operator*=(const modint &r) noexcept {
    mVal = mVal * r.mVal % mMOD;
    return *this;
  }

  modint &operator/=(const modint &r) noexcept {
    int a = r.mVal, b = mMOD, u = 1, v = 0;
    while (b) {
      int t = a / b;
      a -= t * b;
      swap(a, b);
      u -= t * v;
      swap(u, v);
    }
    mVal = mVal * u % mMOD;
    if (mVal < 0)
      mVal += mMOD;
    return *this;
  }

  constexpr bool operator==(const modint &r) const noexcept {
    return this->mVal == r.mVal;
  }

  constexpr bool operator!=(const modint &r) const noexcept {
    return this->mVal != r.mVal;
  }

  constexpr bool operator>(const modint &r) const noexcept {
    return this->mVal > r.mVal;
  }

  constexpr bool operator<(const modint &r) const noexcept {
    return this->mVal < r.mVal;
  }

  constexpr bool operator>=(const modint &r) const noexcept {
    return this->mVal >= r.mVal;
  }

  constexpr bool operator<=(const modint &r) const noexcept {
    return this->mVal <= r.mVal;
  }

  friend ostream &operator<<(ostream &os, const modint &x) noexcept {
    return os << x.mVal;
  }

  friend istream &operator>>(istream &is, modint &x) noexcept {
    return is >> x.mVal;
  }

  constexpr operator int() const noexcept { return mVal; }

  constexpr modint operator+(const int &r) const noexcept {
    return modint(*this) += r;
  }

  constexpr modint operator-(const int &r) const noexcept {
    return modint(*this) -= r;
  }

  constexpr modint operator*(const int &r) const noexcept {
    return modint(*this) *= r;
  }

  modint operator/(const int &r) const noexcept { return modint(*this) /= r; }

  constexpr modint &operator+=(const int &r) noexcept {
    mVal += r;
    if (mVal > mMOD)
      mVal -= mMOD;
    return *this;
  }

  constexpr modint &operator-=(const int &r) noexcept {
    mVal -= r;
    if (mVal < 0)
      mVal += mMOD;
    return *this;
  }

  constexpr modint &operator*=(const int &r) noexcept {
    mVal = mVal * r % mMOD;
    return *this;
  }

  modint &operator/=(const int &r) noexcept {
    int a = r, b = mMOD, u = 1, v = 0;
    while (b) {
      int t = a / b;
      a -= t * b;
      swap(a, b);
      u -= t * v;
      swap(u, v);
    }
    mVal = mVal * u % mMOD;
    if (mVal < 0)
      mVal += mMOD;
    return *this;
  }

  constexpr bool operator==(const int &r) const noexcept {
    return this->mVal == r;
  }

  constexpr bool operator!=(const int &r) const noexcept {
    return this->mVal != r;
  }

  constexpr bool operator>(const int &r) const noexcept {
    return this->mVal > r;
  }

  constexpr bool operator<(const int &r) const noexcept {
    return this->mVal < r;
  }

  constexpr bool operator>=(const int &r) const noexcept {
    return this->mVal >= r;
  }

  constexpr bool operator<=(const int &r) const noexcept {
    return this->mVal <= r;
  }
};

using mint = modint<MOD>; // MODを入力

constexpr mint modpow(const mint &a, int n) noexcept {
  if (n == 0)
    return 1;
  auto t = modpow(a, n / 2);
  t = t * t;
  if (n & 1)
    t = t * a;
  return t;
}

mint modconv(mint n, mint r) noexcept {
  if (n < r)
    return 0;
  else {
    mint res = 1;
    for (int i = 0; i < r; i++) {
      res *= n - i;
    }
    for (int i = 0; i < r; i++) {
      res /= r - i;
    }
    return res;
  }
}

signed main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cout.precision(20);

  mint n, m;
  cin >> n >> m;
  vector<mint> a(m);
  vector<bool> f(m + 1ll, false);
  REP(i, m) {
    cin >> a[i];
    f[a[i]] = true;
  }

  vector<mint> dp(n + 1ll);
  dp[0] = dp[1] = 1;
  FOR(now, 2, n + 1ll) {
    FOR(prev, now - 2, now) {
      if (!f[prev]) {
        dp[now] += dp[prev];
      }
    }
  }

  cout << dp[n] << endl;

  return 0;
}

Fixed submission:
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
// #define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL << 60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define RFOR(i, a, b) for (int i = (int)(b - 1); i >= (int)(a); --i)
#define REP(i, n) FOR(i, 0, (n))
#define RREP(i, n) RFOR(i, 0, (n))
#define ITR(itr, mp) for (auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr, mp) for (auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i, a, b) ((a) <= (i) && (i) < (b))
#define debug(x) cout << #x << " = " << (x) << endl;
#define SP << " " <<
typedef pair<int, int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

template <int mod = MOD> class modint {
private:
  int mMOD = mod, mVal;

public:
  constexpr modint(int v = 0) noexcept : mVal(v % mMOD) {
    if (mVal < 0)
      mVal += mMOD;
  }

  constexpr int getMOD() { return mMOD; }

  constexpr modint operator-() const noexcept { return mVal ? mMOD - mVal : 0; }

  constexpr modint operator+(const modint &r) const noexcept {
    return modint(*this) += r;
  }

  constexpr modint operator-(const modint &r) const noexcept {
    return modint(*this) -= r;
  }

  constexpr modint operator*(const modint &r) const noexcept {
    return modint(*this) *= r;
  }

  modint operator/(const modint &r) const noexcept {
    return modint(*this) /= r;
  }

  constexpr modint &operator+=(const modint &r) noexcept {
    mVal += r.mVal;
    if (mVal > mMOD)
      mVal -= mMOD;
    return *this;
  }

  constexpr modint &operator-=(const modint &r) noexcept {
    mVal -= r.mVal;
    if (mVal < 0)
      mVal += mMOD;
    return *this;
  }

  constexpr modint &operator*=(const modint &r) noexcept {
    mVal = mVal * r.mVal % mMOD;
    return *this;
  }

  modint &operator/=(const modint &r) noexcept {
    int a = r.mVal, b = mMOD, u = 1, v = 0;
    while (b) {
      int t = a / b;
      a -= t * b;
      swap(a, b);
      u -= t * v;
      swap(u, v);
    }
    mVal = mVal * u % mMOD;
    if (mVal < 0)
      mVal += mMOD;
    return *this;
  }

  constexpr bool operator==(const modint &r) const noexcept {
    return this->mVal == r.mVal;
  }

  constexpr bool operator!=(const modint &r) const noexcept {
    return this->mVal != r.mVal;
  }

  constexpr bool operator>(const modint &r) const noexcept {
    return this->mVal > r.mVal;
  }

  constexpr bool operator<(const modint &r) const noexcept {
    return this->mVal < r.mVal;
  }

  constexpr bool operator>=(const modint &r) const noexcept {
    return this->mVal >= r.mVal;
  }

  constexpr bool operator<=(const modint &r) const noexcept {
    return this->mVal <= r.mVal;
  }

  friend ostream &operator<<(ostream &os, const modint &x) noexcept {
    return os << x.mVal;
  }

  friend istream &operator>>(istream &is, modint &x) noexcept {
    return is >> x.mVal;
  }

  constexpr operator int() const noexcept { return mVal; }

  constexpr modint operator+(const int &r) const noexcept {
    return modint(*this) += r;
  }

  constexpr modint operator-(const int &r) const noexcept {
    return modint(*this) -= r;
  }

  constexpr modint operator*(const int &r) const noexcept {
    return modint(*this) *= r;
  }

  modint operator/(const int &r) const noexcept { return modint(*this) /= r; }

  constexpr modint &operator+=(const int &r) noexcept {
    mVal += r;
    if (mVal > mMOD)
      mVal -= mMOD;
    return *this;
  }

  constexpr modint &operator-=(const int &r) noexcept {
    mVal -= r;
    if (mVal < 0)
      mVal += mMOD;
    return *this;
  }

  constexpr modint &operator*=(const int &r) noexcept {
    mVal = mVal * r % mMOD;
    return *this;
  }

  modint &operator/=(const int &r) noexcept {
    int a = r, b = mMOD, u = 1, v = 0;
    while (b) {
      int t = a / b;
      a -= t * b;
      swap(a, b);
      u -= t * v;
      swap(u, v);
    }
    mVal = mVal * u % mMOD;
    if (mVal < 0)
      mVal += mMOD;
    return *this;
  }

  constexpr bool operator==(const int &r) const noexcept {
    return this->mVal == r;
  }

  constexpr bool operator!=(const int &r) const noexcept {
    return this->mVal != r;
  }

  constexpr bool operator>(const int &r) const noexcept {
    return this->mVal > r;
  }

  constexpr bool operator<(const int &r) const noexcept {
    return this->mVal < r;
  }

  constexpr bool operator>=(const int &r) const noexcept {
    return this->mVal >= r;
  }

  constexpr bool operator<=(const int &r) const noexcept {
    return this->mVal <= r;
  }
};

using mint = modint<MOD>; // MODを入力

constexpr mint modpow(const mint &a, int n) noexcept {
  if (n == 0)
    return 1;
  auto t = modpow(a, n / 2);
  t = t * t;
  if (n & 1)
    t = t * a;
  return t;
}

mint modconv(mint n, mint r) noexcept {
  if (n < r)
    return 0;
  else {
    mint res = 1;
    for (int i = 0; i < r; i++) {
      res *= n - i;
    }
    for (int i = 0; i < r; i++) {
      res /= r - i;
    }
    return res;
  }
}

signed main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cout.precision(20);

  mint n, m;
  cin >> n >> m;
  vector<mint> a(m);
  vector<bool> f(n, false);
  REP(i, m) {
    cin >> a[i];
    f[a[i]] = true;
  }

  vector<mint> dp(n + 1ll);
  dp[0] = dp[1] = 1;
  FOR(now, 2, n + 1ll) {
    FOR(prev, now - 2, now) {
      if (!f[prev]) {
        dp[now] += dp[prev];
      }
    }
  }

  cout << dp[n] << endl;

  return 0;
}