Problem p00935 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <array>
#include <cassert>
#include <complex>
#include <ctype.h> // isdigit
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define ALL(u) begin(u), end(u)
#define PB push_back
#define LE(n, m) ((n) < (m) + EPS * (abs(n) + abs(m)))
#define GE(n, m) ((n) + EPS * (abs(n) + abs(m)) > (m))
#define LT(n, m) ((n) + EPS * (abs(n) + abs(m)) < (m))
#define GT(n, m) ((n) > (m) + EPS * (abs(n) + abs(m)))
#define EQ(n, m) (abs((n) - (m)) < EPS * (abs(n) + abs(m)))

typedef long long int ll;
const int INF = (1 << 30) - 1;
const double EPS = 1e-9;
const int MOD = 1000000007;

// g++ -std=c++0x -msse4.2 -O3
// #include <bits/stdc++.h>
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout.precision(16);
  // cout.setf(ios::fixed);

  int N;
  cin >> N;

  vector<int> inputs(N);
  for (auto &v : inputs)
    cin >> v;

  vector<int> exists(1000, false);
  for (int l = 1; l <= 4; l++) {
    for (int i = 0; i < N + 1 - l; i++) {
      int v = 0;
      for (int j = 0; j < l; j++)
        v = v * 10 + inputs[i + j];
      exists[v] = true;
    }
  }

  for (int i = 0; i < 1000; i++) {
    if (!exists[i]) {
      cout << i << endl;
      return 0;
    }
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <array>
#include <cassert>
#include <complex>
#include <ctype.h> // isdigit
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define ALL(u) begin(u), end(u)
#define PB push_back
#define LE(n, m) ((n) < (m) + EPS * (abs(n) + abs(m)))
#define GE(n, m) ((n) + EPS * (abs(n) + abs(m)) > (m))
#define LT(n, m) ((n) + EPS * (abs(n) + abs(m)) < (m))
#define GT(n, m) ((n) > (m) + EPS * (abs(n) + abs(m)))
#define EQ(n, m) (abs((n) - (m)) < EPS * (abs(n) + abs(m)))

typedef long long int ll;
const int INF = (1 << 30) - 1;
const double EPS = 1e-9;
const int MOD = 1000000007;

// g++ -std=c++0x -msse4.2 -O3
// #include <bits/stdc++.h>
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout.precision(16);
  // cout.setf(ios::fixed);

  int N;
  cin >> N;

  vector<int> inputs(N);
  for (auto &v : inputs)
    cin >> v;

  vector<int> exists(1000, false);
  for (int l = 1; l <= 3; l++) {
    for (int i = 0; i < N + 1 - l; i++) {
      int v = 0;
      for (int j = 0; j < l; j++)
        v = v * 10 + inputs[i + j];
      exists[v] = true;
    }
  }

  for (int i = 0; i < 1000; i++) {
    if (!exists[i]) {
      cout << i << endl;
      return 0;
    }
  }

  return 0;
}