Problem p03013 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)

class mod {
public:
  mod() { m_n = 0; }
  mod(ll n) {
    if (n >= 0)
      m_n = n % MOD;
    else
      m_n = n % MOD + MOD;
  }
  friend bool operator==(const mod &a, const mod &b) { return a.m_n == b.m_n; }
  friend bool operator!=(const mod &a, const mod &b) { return !(a == b); }
  friend mod operator+(const mod &a, const mod &b) {
    return (a.m_n + b.m_n) % MOD;
  }
  friend mod &operator+=(mod &a, const mod &b) { return a = a + b; }
  friend mod operator-(const mod &a) { return -a.m_n; }
  friend mod operator-(const mod &a, const mod &b) {
    return (a.m_n + (-b.m_n)) % MOD;
  }
  friend mod &operator-=(mod &a, const mod &b) { return a = a - b; }
  friend mod operator*(const mod &a, const mod &b) {
    return (a.m_n * b.m_n) % MOD;
  }
  friend mod &operator*=(mod &a, const mod &b) { return a = a * b; }
  friend mod mod_pow(const mod &n, ll r) {
    if (r == 0) {
      return 1;
    } else if (r < 0) {
      return mod_pow(n, (MOD - 2) * (-r));
    } else if (r % 2 == 0) {
      mod tmp = mod_pow(n, r / 2);
      return tmp * tmp;
    } else {
      return n * mod_pow(n, r - 1);
    }
  }
  friend mod operator/(const mod &a, const mod &b) {
    return a * mod_pow(b, -1);
  }
  friend mod &operator/=(mod &a, const mod &b) { return a = a / b; }
  friend ostream &operator<<(ostream &os, const mod &n) {
    os << n.m_n;
    return os;
  }
  friend istream &operator>>(istream &is, mod &n) {
    ll tmp;
    is >> tmp;
    n = mod(tmp);
    return is;
  }

private:
  ll m_n;
};

int main(int argc, const char *argv[]) {
  ios_base::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<int> A(M);
  for (int m = 0; m < M; ++m)
    cin >> A[m];
  vector<mod> DP(N + 1);
  DP[0] = 1;
  int mTmp = 0;
  for (int n = 1; n <= N; ++n) {
    if (A[mTmp] == n) {
      DP[n] = 0;
      ++mTmp;
    } else {
      DP[n] = DP[n - 1];
      if (n >= 2)
        DP[n] += DP[n - 2];
    }
  }
  cout << DP[N] << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)

class mod {
public:
  mod() { m_n = 0; }
  mod(ll n) {
    if (n >= 0)
      m_n = n % MOD;
    else
      m_n = n % MOD + MOD;
  }
  friend bool operator==(const mod &a, const mod &b) { return a.m_n == b.m_n; }
  friend bool operator!=(const mod &a, const mod &b) { return !(a == b); }
  friend mod operator+(const mod &a, const mod &b) {
    return (a.m_n + b.m_n) % MOD;
  }
  friend mod &operator+=(mod &a, const mod &b) { return a = a + b; }
  friend mod operator-(const mod &a) { return -a.m_n; }
  friend mod operator-(const mod &a, const mod &b) {
    return (a.m_n + (-b.m_n)) % MOD;
  }
  friend mod &operator-=(mod &a, const mod &b) { return a = a - b; }
  friend mod operator*(const mod &a, const mod &b) {
    return (a.m_n * b.m_n) % MOD;
  }
  friend mod &operator*=(mod &a, const mod &b) { return a = a * b; }
  friend mod mod_pow(const mod &n, ll r) {
    if (r == 0) {
      return 1;
    } else if (r < 0) {
      return mod_pow(n, (MOD - 2) * (-r));
    } else if (r % 2 == 0) {
      mod tmp = mod_pow(n, r / 2);
      return tmp * tmp;
    } else {
      return n * mod_pow(n, r - 1);
    }
  }
  friend mod operator/(const mod &a, const mod &b) {
    return a * mod_pow(b, -1);
  }
  friend mod &operator/=(mod &a, const mod &b) { return a = a / b; }
  friend ostream &operator<<(ostream &os, const mod &n) {
    os << n.m_n;
    return os;
  }
  friend istream &operator>>(istream &is, mod &n) {
    ll tmp;
    is >> tmp;
    n = mod(tmp);
    return is;
  }

private:
  ll m_n;
};

int main(int argc, const char *argv[]) {
  ios_base::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<int> A(M + 1);
  for (int m = 0; m < M; ++m)
    cin >> A[m];
  vector<mod> DP(N + 1);
  DP[0] = 1;
  int mTmp = 0;
  for (int n = 1; n <= N; ++n) {
    if (A[mTmp] == n) {
      DP[n] = 0;
      ++mTmp;
    } else {
      DP[n] = DP[n - 1];
      if (n >= 2)
        DP[n] += DP[n - 2];
    }
  }
  cout << DP[N] << endl;

  return 0;
}