alexjercan/bugnet huggingface dataset:
Problem p00927 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define double long double
#define N 10
using namespace std;
typedef pair<bool, double> P;

const double EPS = 1e-12;

double d, n, b, p[N], h[N];

P check(double s, double A, int cnt) {

  double l = 0, r = 1000000000;

  while (l + EPS < r) {

    double m = (l + r) / 2.0;
    double vx = m * cos(s);
    double vy = m * sin(s);
    double x = vx * 2 * vy;

    if (x < A)
      l = m;
    else
      r = m;
  }

  double vx = l * cos(s);
  double vy = l * sin(s);

  bool res = true;

  double x = 0;

  for (int i = 0; i <= cnt; i++) {

    for (int j = 0; j < n; j++)

      if (x - EPS < p[j] && p[j] < x + A + EPS) {

        if (abs(p[j] - x) < EPS || abs(p[j] - x) < EPS)
          res = false;

        double X = abs(p[j] - x);

        if (-X * X / (2 * vx * vx) + X * vy / vx <= h[j] + EPS)
          res = false;
      }

    x += A;
  }

  return P(res, l);
}

double sim(int cnt) {

  double A = 1.0 * d / (cnt + 1);

  double l = M_PI / 4.0, r = M_PI / 2.0;

  while (l + EPS < r) {

    double m = (l + r) / 2.0;

    if (!check(m, A, cnt).first)
      l = m;
    else
      r = m;
  }

  return check(l, A, cnt).second;
}

int main() {

  cin >> d >> n >> b;

  for (int i = 0; i < n; i++)
    cin >> p[i] >> h[i];

  double ans = (1e9);

  for (int i = 0; i <= b; i++)
    ans = min(ans, sim(i));

  printf("%.8Lf\\n", ans);

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define N 10
using namespace std;
typedef pair<bool, double> P;

const double EPS = 1e-11;
const double EPS2 = 1e-11;
double d, n, b, p[N], h[N];

P check(double s, double A, int cnt) {

  double l = 0, r = 1000000000;

  while (l + EPS2 < r) {

    double m = (l + r) / 2.0;
    double vx = m * cos(s);
    double vy = m * sin(s);
    double x = vx * 2 * vy;

    if (x < A)
      l = m;
    else
      r = m;
  }

  double vx = l * cos(s);
  double vy = l * sin(s);

  bool res = true;

  double x = 0;

  for (int i = 0; i <= cnt; i++) {

    for (int j = 0; j < n; j++)

      if (x - EPS < p[j] && p[j] < x + A + EPS) {

        if (abs(p[j] - x) < EPS || abs(p[j] - x) < EPS)
          res = false;

        double X = abs(p[j] - x);

        if (-X * X / (2 * vx * vx) + X * vy / vx <= h[j] + EPS)
          res = false;
      }

    x += A;
  }

  return P(res, l);
}

double sim(int cnt) {

  double A = 1.0 * d / (cnt + 1);

  double l = M_PI / 4.0, r = M_PI / 2.0;

  while (l + EPS2 < r) {

    double m = (l + r) / 2.0;

    if (!check(m, A, cnt).first)
      l = m;
    else
      r = m;
  }

  return check(l, A, cnt).second;
}

int main() {

  cin >> d >> n >> b;

  for (int i = 0; i < n; i++)
    cin >> p[i] >> h[i];

  double ans = (1e9);

  for (int i = 0; i <= b; i++)
    ans = min(ans, sim(i));

  printf("%.8f\\n", ans);

  return 0;
}
Problem p00929 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <vector>

#define phb push_back
#define mkp make_pair
#define frs first
#define scn second
#define sz(x) int((x).size())
using namespace std;

const int kInf = 1000000000;
typedef pair<int, int> Pr;
typedef pair<int, Pr> Prr;

int N, M;
Prr E[50010];
vector<int> NE;

int nset[510];

void read();
void solve();
int kruskal(int);

int find_set(int x) {
  if (~nset[x])
    return nset[x] = find_set(nset[x]);
  return x;
}

void union_set(int x, int y) { nset[find_set(y)] = find_set(x); }

bool cmpf(const Prr &, const Prr &);

int main() {
  read();
  solve();
  return 0;
}

void read() {
  int u, v, c;

  cin >> N >> M;
  for (int i = 0; i < M; ++i) {
    cin >> u >> v >> c;
    E[i] = mkp(c, mkp(u, v));
  }
}

void solve() {
  int res, mcst, csum;

  stable_sort(&E[0], &E[M], cmpf);
  mcst = kruskal(-1);

  res = csum = 0;
  for (int i = 0; i < N - 1; ++i)
    if (kruskal(NE[i]) > mcst)
      ++res, csum += E[NE[i]].frs;

  cout << res << " " << csum << "\\n";
}

int kruskal(int fid) {
  fill(&nset[0], &nset[510], -1);

  int i, j, ret = 0;

  if (fid == -1) {
    for (i = j = 0; i < M && j < N - 1; ++i) {
      int u = E[i].scn.frs, v = E[i].scn.scn;

      if (find_set(u) != find_set(v))
        ret += E[i].frs, union_set(u, v), ++j, NE.phb(i);
    }
  } else {
    for (i = j = 0; i < M && j < N - 1; ++i) {
      if (i == fid)
        continue;

      int u = E[i].scn.frs, v = E[i].scn.scn;

      if (find_set(u) != find_set(v))
        ret += E[i].frs, union_set(u, v), ++j;
    }
  }

  return j == N - 1 ? ret : kInf;
}

bool cmpf(const Prr &ra, const Prr &rb) { return ra.frs < rb.frs; }

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>

#define mkp make_pair
#define frs first
#define scn second
using namespace std;

const int kInf = 1000000000;
typedef pair<int, int> Pr;
typedef pair<int, Pr> Prr;

int N, M;
Prr E[50010];

int nset[510];

void read();
void solve();
int kruskal(int);

int find_set(int x) {
  if (~nset[x])
    return nset[x] = find_set(nset[x]);
  return x;
}

void union_set(int x, int y) { nset[find_set(y)] = find_set(x); }

bool cmpf(const Prr &, const Prr &);

int main() {
  read();
  solve();
  return 0;
}

void read() {
  int u, v, c;

  cin >> N >> M;
  for (int i = 0; i < M; ++i) {
    cin >> u >> v >> c;
    E[i] = mkp(c, mkp(u, v));
  }
}

void solve() {
  int res, mcst, csum;

  stable_sort(&E[0], &E[M], cmpf);
  mcst = kruskal(-1);

  res = csum = 0;
  for (int i = 0; i < M; ++i)
    if (kruskal(i) > mcst)
      ++res, csum += E[i].frs;

  cout << res << " " << csum << "\\n";
}

int kruskal(int fid) {
  fill(&nset[0], &nset[510], -1);

  int i, j, ret = 0;

  for (i = j = 0; i < M && j < N - 1; ++i) {
    if (i == fid)
      continue;

    int u = E[i].scn.frs, v = E[i].scn.scn;

    if (find_set(u) != find_set(v))
      ret += E[i].frs, union_set(u, v), ++j;
  }

  return j == N - 1 ? ret : kInf;
}

bool cmpf(const Prr &ra, const Prr &rb) { return ra.frs < rb.frs; }
Problem p00929 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

struct edge {
  int from, to, cost;
  bool operator<(const edge &p) const { return cost < p.cost; }
};

int pa[1000], ra[1000];
void init() {
  for (int i = 0; i < 1000; i++) {
    pa[i] = i;
    ra[i] = 0;
  }
}

int find(int x) {
  if (x == pa[x])
    return x;
  else
    return pa[x] = find(pa[x]);
}

bool same(int x, int y) { return find(x) == find(y); }

void unite(int x, int y) {
  x = find(x), y = find(y);
  if (ra[x] < ra[y])
    swap(x, y);
  pa[y] = x;
  if (ra[x] == ra[y])
    ra[x]++;
}

int N, M;
int a, b, c;
int flg[100000];
vector<edge> t;

int solve(int id) {
  int sum = 0;
  for (int i = 0; i < (int)t.size(); i++) {
    if (i == id)
      continue;
    edge e = t[i];
    if (same(e.from, e.to))
      continue;
    unite(e.from, e.to);
    sum += e.cost;
    if (id == -1)
      flg[i] = true;
  }
  if (id != -1) {
    edge e = t[id];
    if (same(e.from, e.to))
      return sum;
    else
      return 1e9;
  }
  return sum;
}

int main() {
  cin >> N >> M;
  init();
  t.clear();
  for (int i = 0; i < M; i++) {
    scanf("%d %d %d", &a, &b, &c);
    t.push_back((edge){a, b, c});
  }
  sort(t.begin(), t.end());
  int base = solve(-1);

  int ans = 0, ans2 = 0;
  for (int i = 0; i < M; i++) {
    if (flg[i] == false)
      continue;
    init();
    int b = solve(i);

    if (base == b)
      continue;
    ans++;
    ans2 += t[i].cost;
  }
  cout << ans << ' ' << ans2 << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

struct edge {
  int from, to, cost;
  bool operator<(const edge &p) const { return cost < p.cost; }
};

int pa[1000], ra[1000];
void init() {
  for (int i = 0; i < 1000; i++) {
    pa[i] = i;
    ra[i] = 0;
  }
}

int find(int x) {
  if (x == pa[x])
    return x;
  else
    return pa[x] = find(pa[x]);
}

bool same(int x, int y) { return find(x) == find(y); }

void unite(int x, int y) {
  x = find(x), y = find(y);
  if (ra[x] < ra[y])
    swap(x, y);
  pa[y] = x;
  if (ra[x] == ra[y])
    ra[x]++;
}

int N, M;
int a, b, c;
int flg[1000];
vector<edge> t;

int solve(int id) {
  int sum = 0;
  for (int i = 0; i < (int)t.size(); i++) {
    if (i == id)
      continue;
    edge e = t[i];
    if (same(e.from, e.to))
      continue;
    unite(e.from, e.to);
    sum += e.cost;
    if (id == -1)
      flg[i] = true;
  }
  if (id != -1) {
    edge e = t[id];
    if (same(e.from, e.to))
      return sum;
    else
      return 1e9;
  }
  return sum;
}

int main() {
  cin >> N >> M;
  init();
  t.clear();
  for (int i = 0; i < M; i++) {
    scanf("%d %d %d", &a, &b, &c);
    t.push_back((edge){a, b, c});
  }
  sort(t.begin(), t.end());
  int base = solve(-1);

  int ans = 0, ans2 = 0;
  for (int i = 0; i < M; i++) {
    if (flg[i] == false)
      continue;
    init();
    int b = solve(i);

    if (base == b)
      continue;
    ans++;
    ans2 += t[i].cost;
  }
  cout << ans << ' ' << ans2 << endl;
  return 0;
}
Problem p00929 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
const int maxn = 500000;
struct arc {
  int u, v, w;
  bool used, mark, del;
  arc(int x = 0, int y = 0, int z = 0) {
    u = x;
    v = y;
    w = z;
    mark = del = used = false;
  }
  bool operator<(const arc &tmp) const { return w < tmp.w; }
} e[maxn];
int uf[maxn], n, m, cnt;
bool nui[maxn];
int Find(int x) { return uf[x] = uf[x] == x ? uf[x] : Find(uf[x]); }
int kruskal(bool &Unique, bool first) {
  int ans = cnt = 0;
  for (int i = 0; i <= n; ++i)
    uf[i] = i;
  for (int i = 0; i < m; ++i) {
    if (!first && e[i].del)
      continue;
    int fx = Find(e[i].u);
    int fy = Find(e[i].v);
    if (fx == fy)
      continue;
    uf[fx] = fy;
    ans += e[i].w;
    if (first) {
      e[i].used = true;
      if (e[i].mark)
        Unique = false;
    }
    if (++cnt == n - 1)
      return ans;
  }
  return ans;
}
int main() {
  int u, v, w;
  while (~scanf("%d %d", &n, &m)) {
    for (int i = 0; i < m; ++i) {
      scanf("%d %d %d", &u, &v, &w);
      e[i] = arc(u, v, w);
    }
    memset(nui, false, sizeof(nui));
    sort(e, e + m);
    for (int i = 1; i < m; ++i)
      if (e[i].w == e[i - 1].w)
        e[i].mark = e[i - 1].mark = true;
    bool Unique = true;
    int MST = kruskal(Unique, true);
    if (Unique)
      printf("%d %d\\n", n - 1, MST);
    else {
      int mst = 0, ne = 0;
      for (int i = 0; i < m; ++i) {
        if (e[i].used && e[i].mark) {
          e[i].del = true;
          int tmp = kruskal(Unique, false);
          if (tmp == MST && cnt == n - 1)
            nui[i] = true;
          e[i].del = false;
        }
        if (e[i].used && !nui[i]) {
          ne++;
          mst += e[i].w;
        }
      }
      printf("%d %d\\n", ne, mst);
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string.h>
#include <vector>
#define INF 0x3f3f3f3f
using namespace std;
long long need, ans;
int n, m, res1, res2;
struct line {
  int s, e, cost;
  friend bool operator<(const line &a, const line &b) {
    return a.cost < b.cost;
  }
} num[50010], nu[50010];
int edge[510][510], bingcha[510];

int find(int x) {
  if (x == bingcha[x])
    return x;
  else
    return find(bingcha[x]);
}

void init() {
  for (int i = 0; i < 510; i++)
    bingcha[i] = i;
  ans = 0;
}

int kruscal(line n[]) {
  init();
  int need = 0;
  sort(n, n + m);
  for (int i = 0; i < m; i++) {
    int x = find(n[i].s);
    int y = find(n[i].e);

    if (x != y) {
      bingcha[x] = y;
      need += n[i].cost;
    }
  }
  return need;
}
int main() {
  // freopen("data.in","r",stdin);
  scanf("%d%d", &n, &m);
  res1 = 0, res2 = 0;
  for (int i = 0; i < m; i++) {
    scanf("%d%d%d", &num[i].s, &num[i].e, &num[i].cost);
  }
  need = kruscal(num);
  for (int i = 0; i < m; i++) {
    memcpy(nu, num, sizeof(num));
    int tmp = nu[i].cost;
    nu[i].cost = INF;
    ans = kruscal(nu);
    if (ans > need) {
      res1++;
      res2 += tmp;
    }
  }
  printf("%d %d\\n", res1, res2);
}
Problem p00935 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
const int maxn = 20001;
int a[maxn], b[maxn];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) {
    b[a[i]]++;
    if (i + 1 <= n)
      b[a[i] * 10 + a[i + 1]]++;
    if (i + 2 <= n)
      b[a[i] * 100 + a[i + 1] * 10 + a[i + 2]]++;
    if (i + 3 <= n)
      b[a[i] * 1000 + a[i + 1] * 100 + a[i + 2] * 10 + a[i + 3]]++;
  }
  for (int i = 0; i <= 10000; i++)
    if (!b[i]) {
      cout << i << endl;
      break;
    }
  // while(1);
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <queue>
#include <string>
using namespace std;
int a[1005], n, m, k, i, r, l, j, p = 0, b[1005] = {0};
int main() {
  // freopen(".in","r",stdin);
  // freopen(".out","w",stdout);
  cin >> n;
  for (i = 1; i <= n; i++)
    cin >> a[i];
  sort(a + 1, a + n + 1);
  for (i = 1; i <= n; i++) {
    for (l = 1; l <= n - i + 1; l++) {
      if (a[l] != 0 || l == 1) {
        for (j = l; j <= l + i - 1; j++)
          p = p * 10 + a[j];
        b[p] = 1;
        p = 0;
      }
    }
  }
  for (i = 1; i <= 1000; i++)
    if (b[i] == 0) {
      cout << i << endl;
      return 0;
    }
  return 0;
}
Problem p00935 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;

bool vis[100005];
int n, x, a[1005];

int main() {
  memset(vis, false, sizeof(vis));
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) {
    x = 0;
    for (int j = 0; j <= min(4, n - i); j++) {
      x = x * 10 + a[i + j];
      vis[x] = true;
    }
  }
  for (int i = 0; i <= 100000; i++) {
    if (vis[i] == false) {
      printf("%d\\n", i);
      break;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;

bool vis[100005];
int n, x, a[1005];

int main() {
  memset(vis, false, sizeof(vis));
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) {
    x = 0;
    for (int j = 0; j <= min(5, n - i); j++) {
      x = x * 10 + a[i + j];
      vis[x] = true;
    }
  }
  for (int i = 0; i <= 100000; i++) {
    if (vis[i] == false) {
      printf("%d\\n", i);
      break;
    }
  }
  return 0;
}
Problem p00935 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int, int> pii;
#define REP(i, n) for (ll i = 0; i < n; ++i)
#define REPR(i, n) for (ll i = 1; i < n; ++i)
#define FOR(i, a, b) for (ll i = a; i < b; ++i)

#define DEBUG(x) cout << #x << ": " << x << endl
#define DEBUG_VEC(v)                                                           \\
  cout << #v << ":";                                                           \\
  REP(i, v.size()) cout << " " << v[i];                                        \\
  cout << endl
#define ALL(a) (a).begin(), (a).end()

#define MOD (ll)(1e9 + 7)
#define ADD(a, b) a = ((a) + (b)) % MOD
#define FIX(a) ((a) % MOD + MOD) % MOD

int main() {
  int n;
  cin >> n;
  int a[n];
  REP(i, n) cin >> a[i];

  set<ll> ss;
  REP(i, n) {
    if (a[i] == 0) {
      ss.insert(0);
      continue;
    }
    ll tmp = 0;
    REP(j, 5) {
      if (i + j >= n)
        break;
      tmp *= 10;
      tmp += a[i + j];
      ss.insert(tmp);
    }
  }
  set<ll>::iterator iter;
  ll f = 0;
  iter = ss.begin();
  while (iter != ss.end()) {
    if (*iter != f)
      break;
    ++f;
    ++iter;
  }
  cout << f << endl;
  return 0;
}

Error: MLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int, int> pii;
#define REP(i, n) for (ll i = 0; i < n; ++i)
#define REPR(i, n) for (ll i = 1; i < n; ++i)
#define FOR(i, a, b) for (ll i = a; i < b; ++i)

#define DEBUG(x) cout << #x << ": " << x << endl
#define DEBUG_VEC(v)                                                           \\
  cout << #v << ":";                                                           \\
  REP(i, v.size()) cout << " " << v[i];                                        \\
  cout << endl
#define ALL(a) (a).begin(), (a).end()

#define MOD (ll)(1e9 + 7)
#define ADD(a, b) a = ((a) + (b)) % MOD
#define FIX(a) ((a) % MOD + MOD) % MOD

struct Comp {
  bool operator()(const string l, const string r) {
    if (l.size() != r.size())
      return l.size() < r.size();
    return l < r;
  }
};

string succ(string a) {
  if (a.size() == 0)
    return "1";
  if (a[a.size() - 1] != '9') {
    a[a.size() - 1] += 1;
  } else {
    a = succ(a.substr(0, a.size() - 1)) + "0";
  }
  return a;
}

int main() {
  int n;
  cin >> n;
  int a[n];
  REP(i, n) cin >> a[i];
  set<string, Comp> ss;
  REP(i, n) {
    if (a[i] == 0) {
      ss.insert("0");
      continue;
    }
    string t = "";
    FOR(j, i, n) {
      t += (a[j] + '0');
      ss.insert(t);
    }
  }
  string now = "0";
  set<string, Comp>::iterator iter;
  for (iter = ss.begin(); iter != ss.end(); ++iter) {
    // DEBUG(*iter);
    if (now == *iter) {
      now = succ(now);
    } else {
      break;
    }
  }
  cout << now << endl;
  return 0;
}
Problem p00935 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <iostream>
#include <set>
#include <string>
#include <vector>

using namespace std;

int N;

int main() {
  cin >> N;
  vector<int> d(N);
  for (auto &v : d)
    cin >> v;
  set<string> S;
  for (int i = 0; i < N; i++) {
    string s = "";
    for (int j = i; j < min(i + 5, N); j++) {
      s += to_string(d[j]);
      S.insert(s);
    }
  }
  for (int i = 0; i < N * N + 1; i++) {
    if (S.find(to_string(i)) == S.end()) {
      cout << i << endl;
      return 0;
    }
  }

  return 0;
}

Error: MLE

Fixed submission:

#include <iostream>
#include <set>
#include <string>
#include <vector>

using namespace std;

int N;

int main() {
  cin >> N;
  vector<int> d(N);
  for (auto &v : d)
    cin >> v;
  set<string> S;
  for (int i = 0; i < N; i++) {
    string s = "";
    for (int j = i; j < N; j++) {
      s += to_string(d[j]);
      S.insert(s);
    }
  }
  //  for(auto &s: S) cout << s << endl;
  for (int i = 0; i < N * N + 1; i++) {
    if (S.find(to_string(i)) == S.end()) {
      cout << i << endl;
      return 0;
    }
  }

  return 0;
}
Problem p00935 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;

int A[1010], done[1010000];
int n, m;

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &A[i]);
  }
  for (int i = 1; i <= n; i++) {
    int k = 0;
    for (int j = i; j <= min(n, i + 3); j++) {
      k = k * 10 + A[j];
      done[k] = 1;
    }
  }
  for (int i = 0; i <= 10000; i++) {
    if (!done[i]) {
      printf("%d\\n", i);
      return 0;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const double eps = 1e-6;
const int maxn = 1e5 + 5;
const int dx[] = {-1, 0, 1, 0, -1, -1, 1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
int num[maxn], a[1005];
int main() {
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
#endif

  int n;
  while (~scanf("%d", &n)) {
    for (int i = 0; i < n; i++)
      scanf("%d", &a[i]);
    int index = 0;
    for (int i = 1; i <= 5; i++) {
      for (int j = 0; j < n; j++) {
        int tmp = 0;
        for (int k = 0; k < i; k++) {
          if (j + k >= n)
            break;
          tmp *= 10;
          tmp += a[j + k];
        }
        num[index++] = tmp;
      }
    }
    sort(num, num + index);
    int ans = 0;
    for (int i = 1; i < index; i++) {
      if (num[i] - num[i - 1] > 1) {
        ans = num[i - 1] + 1;
        break;
      }
    }
    printf("%d\\n", ans);
  }
}
Problem p00935 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

int n, d[1001];
bool D[1000000] = {};

int main() {
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> d[i];

  reverse(d, d + n);

  for (int i = 0; i < n; i++) {
    int num = d[i], k = 1;
    D[num] = true;
    for (int j = i + 1; j < n; j++) {
      if (k > 4)
        break;
      num += d[j] * pow(10, k);
      D[num] = true;
      k++;
    }
  }
  for (int i = 0; i < 100000; i++) {
    if (!D[i]) {
      cout << i << endl;
      break;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int n, d[1001];
bool D[1000000];

int main() {
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> d[i];

  reverse(d, d + n);

  for (int i = 0; i < n; i++) {
    int num = d[i];
    D[num] = true;
    for (int j = i + 1, k = 1; j < n, k <= 5; j++, k++) {
      num += d[j] * pow(10, k);
      D[num] = true;
    }
  }
  for (int i = 0; i < 1000000; i++) {
    if (!D[i]) {
      cout << i << endl;
      break;
    }
  }
  return 0;
}
Problem p00935 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstring>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

void solve() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  bool used[10000];
  memset(used, 0, sizeof(used));
  int n;
  cin >> n;
  vector<char> s(n);
  for (int i = 0; i < n; ++i) {
    cin >> s[i];
  }
  for (int i = 0; i < n; ++i) {
    int digit = 0;
    for (int j = 0; j < 4 && i + j < n; ++j) {
      digit = digit * 10 + s[i + j] - '0';
      used[digit] = true;
    }
  }
  int pos = 0;
  while (true) {
    if (used[pos] == 0) {
      cout << pos << endl;
      return;
    }
    ++pos;
  }
}

int main() {
  solve();
  return (0);
}

Error: TLE

Fixed submission:

#include <cstring>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

void solve() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  map<long, int> number;
  int n;
  cin >> n;
  vector<char> s(n);
  for (int i = 0; i < n; ++i) {
    cin >> s[i];
  }
  for (int i = 1; i < n; ++i) {
    for (int j = 0; i + j <= n; ++j) {
      long int digit = 0;
      for (int k = 0; k < i; ++k) {
        digit += s[j + k] - '0';
        number[digit]++;
        digit *= 10;
      }
    }
  }
  int pos = 0;
  while (true) {
    if (number[pos] == 0) {
      cout << pos << endl;
      return;
    }
    ++pos;
  }
}

int main() {
  solve();
  return (0);
}