Problem p03013 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define Rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define RRep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define pb push_back
#define eb emplace_back

struct Edge {
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};

using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;

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

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

template <class T> T gcd(T a, T b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}

template <class T> T lcm(T a, T b) { return (a * b) / gcd(a, b); }

int INF = 1e9 + 7;

vector<int> dx = {-1, 0, 1, 0};
vector<int> dy = {0, -1, 0, 1};

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  rep(i, m) cin >> a[i];
  vector<int> dp(n + 1, 0);
  dp[0] = 1;
  int j = 0;
  rep(i, n) {
    if (i + 1 == a[j]) {
      dp[i + 1] = 0;
      j++;
    } else if (i == 0) {
      dp[i + 1] = dp[i];
    } else {
      dp[i + 1] = dp[i] + dp[i - 1];
      dp[i + 1] %= INF;
    }
  }
  cout << dp[n] << endl;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define Rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define RRep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define pb push_back
#define eb emplace_back

struct Edge {
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};

using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;

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

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

template <class T> T gcd(T a, T b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}

template <class T> T lcm(T a, T b) { return (a * b) / gcd(a, b); }

int INF = 1e9 + 7;

vector<int> dx = {-1, 0, 1, 0};
vector<int> dy = {0, -1, 0, 1};

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  rep(i, m) cin >> a[i];
  vector<int> dp(n + 1, 0);
  dp[0] = 1;
  int j = 0;
  rep(i, n) {
    if (j < m && i + 1 == a[j]) {
      dp[i + 1] = 0;
      j++;
    } else if (i == 0) {
      dp[i + 1] = dp[i];
    } else {
      dp[i + 1] = dp[i] + dp[i - 1];
      dp[i + 1] %= INF;
    }
  }
  cout << dp[n] << endl;
}