alexjercan/bugnet huggingface dataset:
Problem p00261 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>
using namespace std;

int main() {
  int node[10][10];
  node[0][0] = 1;
  node[0][1] = 2;
  node[1][0] = -1;
  node[1][1] = 3;
  node[2][0] = 1;
  node[2][1] = -1;
  node[3][0] = 4;
  node[3][1] = 5;
  node[4][0] = 5;
  node[4][1] = 2;
  node[5][0] = 2;
  node[5][1] = 1;
  while (1) {
    string str;
    cin >> str;
    if (str == "#")
      break;
    int len = str.size();
    int now = 0;
    for (int i = 0; i < len; i++) {
      if (now == -1)
        break;
      int f = str[i] - '0';
      now = node[now][f];
    }
    if (now == 5)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
}

Error: 0

Fixed submission:

#include <iostream>
#include <string>
using namespace std;

int main() {
  int node[10][10];
  node[0][0] = 1;
  node[0][1] = 2;
  node[1][0] = -1;
  node[1][1] = 3;
  node[2][0] = 1;
  node[2][1] = -1;
  node[3][0] = 4;
  node[3][1] = 5;
  node[4][0] = 5;
  node[4][1] = 2;
  node[5][0] = 2;
  node[5][1] = 1;
  while (1) {
    string str;
    cin >> str;
    if (str == "#")
      break;
    int len = str.size();
    int now = 0;
    for (int i = 0; i < len; i++) {
      int f = str[i] - '0';
      now = node[now][f];
    }
    if (now == 5)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
}
Problem p00262 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  while (cin >> n, n) {
    int num[2000] = {}, co = n;
    for (int i = 0; i < n; i++)
      cin >> num[i];
    for (int i = 0;; i++) {
      bool kawa = 1;
      if (i == 10000) {
        cout << -1 << endl;
        break;
      }
      for (int j = 0; j < co && kawa; j++)
        if (num[j] != j + 1)
          kawa = 0;
      if (kawa) {
        cout << i << endl;
        break;
      }
      for (int j = 0; j < co; j++)
        num[j] -= 1;
      num[co] = co;
      for (int j = 0; j <= co; j++) {
        if (num[j] == 0) {
          for (int k = j + 1; k <= co; k++) {
            if (num[k] != 0) {
              swap(num[j], num[k]);
              break;
            }
          }
        }
      }
      for (int j = co + 1; j >= 0; j--) {
        if (num[j] != 0) {
          co = j + 1;
          break;
        }
      }
    }
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  while (cin >> n, n) {
    int num[1000] = {}, co = n;
    for (int i = 0; i < n; i++)
      cin >> num[i];
    for (int i = 0;; i++) {
      bool kawa = 1;
      if (i == 10000) {
        cout << -1 << endl;
        break;
      }
      for (int j = 0; j < co && kawa; j++)
        if (num[j] != j + 1)
          kawa = 0;
      if (kawa) {
        cout << i << endl;
        break;
      }
      for (int j = 0; j < co; j++)
        num[j] -= 1;
      num[co] = co;
      for (int j = 0; j <= co; j++) {
        if (num[j] == 0) {
          for (int k = j + 1; k <= co; k++) {
            if (num[k] != 0) {
              swap(num[j], num[k]);
              break;
            }
          }
        }
      }
      for (int j = co + 1; j >= 0; j--) {
        if (num[j] != 0) {
          co = j + 1;
          break;
        }
      }
    }
  }
}
Problem p00262 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int n, V, a[100000];
bool query0() {
  for (int i = 1; i <= V; i++) {
    if (a[i] == 0) {
      return true;
    }
    if (a[i] != i) {
      return false;
    }
  }
  return true;
}
void query1() {
  int cnt = 1, cnt2 = 0;
  for (int i = 1; i <= V; i++) {
    if (a[i] >= 1) {
      int b = a[i];
      a[i] = 0;
      a[cnt] = b;
      cnt++;
      cnt2++;
    }
  }
  V = cnt2;
}
void query2() {
  for (int i = 1; i <= V; i++) {
    a[i]--;
  }
  a[V + 1] = V;
  V++;
}
int main() {
  while (true) {
    for (int i = 0; i < 100000; i++) {
      a[i] = 0;
    }
    cin >> n;
    V = n;
    if (n == 0) {
      break;
    }
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
    }
    int cnt = 0;
    while (true) {
      bool ok = query0();
      if (ok == true) {
        cout << cnt << endl;
        break;
      }
      query1();
      query2();
      query1();
      cnt++;
      if (cnt > 10000) {
        cout << "-1" << endl;
        break;
      }
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int n, V, a[100000];
bool query0() {
  for (int i = 1; i <= V; i++) {
    if (a[i] == 0) {
      return true;
    }
    if (a[i] != i) {
      return false;
    }
  }
  return true;
}
void query1() {
  for (int i = V; i >= 2; i--) {
    if (a[i] == 0) {
      V--;
      a[i] = a[i + 1];
      a[i + 1] = 0;
    }
  }
}
void query2() {
  a[V + 1] = V;
  V++;
}
int main() {
  while (true) {
    cin >> n;
    V = n;
    if (n == 0) {
      break;
    }
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
    }
    int cnt = 0;
    while (true) {
      bool ok = query0();
      if (ok == true) {
        cout << cnt << endl;
        break;
      }
      query1();
      query2();
      cnt++;
    }
  }
  return 0;
}
Problem p00262 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>
using namespace std;
int n, s;
bool triangle(vector<int> v) {
  for (int i = 0; i < v.size(); i++) {
    if (v[i] != i + 1)
      return false;
  }
  return true;
}
vector<int> shift(vector<int> v) {
  vector<int> ret;
  for (int i = 0; i < v.size(); i++) {
    if (v[i])
      ret.push_back(v[i]);
  }
  return ret;
}
int main() {
  while (cin >> n, n) {
    vector<int> v(n);
    s = 0;
    for (int i = 0; i < n; i++)
      cin >> v[i], s += v[i];
    bool flag = false;
    for (int i = 0; i < 2000; i++) {
      if (i * (i + 1) / 2 == s)
        flag = true;
    }
    if (!flag)
      cout << -1 << endl;
    else {
      int c = 0;
      while (c <= 10000) {
        if (triangle(v))
          break;
        for (int i = 0; i < v.size(); i++)
          v[i]--;
        v.push_back(v.size());
        v = shift(v);
        c++;
      }
      cout << (c <= 10000 ? c : -1) << endl;
    }
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
int n, s;
bool triangle(vector<int> v) {
  for (int i = 0; i < v.size(); i++) {
    if (v[i] != i + 1)
      return false;
  }
  return true;
}
vector<int> shift(vector<int> v) {
  vector<int> ret;
  for (int i = 0; i < v.size(); i++) {
    if (v[i])
      ret.push_back(v[i]);
  }
  return ret;
}
int main() {
  while (cin >> n, n) {
    vector<int> v(n);
    s = 0;
    for (int i = 0; i < n; i++)
      cin >> v[i], s += v[i];
    bool flag = false;
    for (int i = 0; i < 2000; i++) {
      if (i * (i + 1) / 2 == s)
        flag = true;
    }
    if (!flag)
      cout << -1 << endl;
    else {
      int c = 0;
      while (true) {
        if (triangle(v))
          break;
        for (int i = 0; i < v.size(); i++)
          v[i]--;
        v.push_back(v.size());
        v = shift(v);
        c++;
      }
      cout << (c <= 10000 ? c : -1) << endl;
    }
  }
}
Problem p00262 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)

int n, b[1000000], bb[1000000];

int main() {
  while (true) {
    cin >> n;
    if (n == 0)
      break;
    rep(i, n) cin >> b[i];
    rep(i, 10001) {
      bool f = true;
      rep(j, n) if (b[j] != j + 1) {
        f = false;
        break;
      }
      if (f) {
        cout << i << endl;
        goto next;
      }
      rep(j, n)-- b[j];
      b[n] = n;
      int k = 0;
      rep(j, n + 1) if (b[j] > 0) bb[k++] = b[j];
      n = k;
      rep(j, n) b[j] = bb[j];
    }
    cout << -1 << endl;
  next:;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)

int main() {
  int n, b[1000], bb[1000];
  while (true) {
    cin >> n;
    if (n == 0)
      break;
    rep(i, n) cin >> b[i];
    rep(i, 10001) {
      bool f = true;
      rep(j, n) if (b[j] != j + 1) {
        f = false;
        break;
      }
      if (f) {
        cout << i << endl;
        goto next;
      }
      rep(j, n)-- b[j];
      b[n] = n;
      int k = 0;
      rep(j, n + 1) if (b[j] > 0) bb[k++] = b[j];
      n = k;
      rep(j, n) b[j] = bb[j];
    }
    cout << -1 << endl;
  next:;
  }
  return 0;
}
Problem p00262 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
  int n;
  while (1) {
    cin >> n;
    if (!n)
      return 0;
    int x[10005];
    for (int i = 0; i < n; i++) {
      cin >> x[i];
    }
    int res = -1;
    for (int i = 0; i <= 10000; i++) {
      for (int j = 0; j < n; j++)
        if (x[j] != j + 1)
          goto nxt;
      res = i;
      break;
    nxt:;
      int cur = 0;
      for (int j = 0; j < n; j++) {
        if (x[j] > 1) {
          x[cur] = x[j] - 1;
          cur++;
        }
      }
      x[cur] = n;
      n = cur + 1;
    }
    cout << res << endl;
  }
}

Error: -6
*** stack smashing detected ***: terminated


Fixed submission:

#include <algorithm>
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
  int n;
  while (1) {
    cin >> n;
    if (!n)
      return 0;
    int x[105];
    for (int i = 0; i < n; i++) {
      cin >> x[i];
    }
    int res = -1;
    for (int i = 0; i <= 10000; i++) {
      for (int j = 0; j < n; j++)
        if (x[j] != j + 1)
          goto nxt;
      res = i;
      break;
    nxt:;
      int cur = 0;
      for (int j = 0; j < n; j++) {
        if (x[j] > 1) {
          x[cur] = x[j] - 1;
          cur++;
        }
      }
      x[cur] = n;
      n = cur + 1;
    }
    cout << res << endl;
  }
}
Problem p00262 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
int b[10000];
int main() {
  int a;
  while (scanf("%d", &a), a) {
    for (int i = 0; i < a; i++)
      scanf("%d", b + i);
    int now = 0;
    int n = a;
    while (1) {
      bool ok = true;
      for (int i = 0; i < n; i++)
        if (b[i] != i + 1)
          ok = false;
      if (ok) {
        printf("%d\\n", now);
        break;
      } else if (now == 10000) {
        printf("-1\\n");
        break;
      }
      now++;
      for (int i = 0; i < n; i++) {
        b[i]--;
      }
      int at = 0;
      for (int i = 0; i < n; i++)
        if (b[i])
          b[at++] = b[i];
      b[at++] = n;
      n = at;
    }
  }
}

Error: 0

Fixed submission:

#include <stdio.h>
int b[100];
int main() {
  int a;
  while (scanf("%d", &a), a) {
    for (int i = 0; i < a; i++)
      scanf("%d", b + i);
    int now = 0;
    int n = a;
    while (1) {
      bool ok = true;
      for (int i = 0; i < n; i++)
        if (b[i] != i + 1)
          ok = false;
      if (ok) {
        printf("%d\\n", now);
        break;
      } else if (now == 10000) {
        printf("-1\\n");
        break;
      }
      now++;
      for (int i = 0; i < n; i++) {
        b[i]--;
      }
      int at = 0;
      for (int i = 0; i < n; i++)
        if (b[i])
          b[at++] = b[i];
      b[at++] = n;
      n = at;
    }
  }
}
Problem p00262 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <list>
#include <vector>
using namespace std;

bool is_finish(list<int> t) {
  int a = 0;
  for (list<int>::iterator it = t.begin(); it != t.end(); it++) {
    if (*it != ++a)
      return false;
  }
  return true;
}

int main() {
  int n;
  list<int> block;
  while (cin >> n, n) {
    int a;
    for (int i = 0; i < n; i++) {
      cin >> a;
      block.push_back(a);
    }

    int ans = 0;
    while (!is_finish(block)) {
      if (ans > 10000)
        break;
      int cnt = 0;

      for (list<int>::iterator it = block.begin(); it != block.end(); it++) {
        (*(it))--;
        cnt++;
      }
      block.push_back(cnt);
      block.remove(0);
      ans++;
    }
    if (ans > 10000)
      cout << -1 << endl;
    else
      cout << ans << endl;
    block.clear();
  }
  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <list>
#include <vector>
using namespace std;

bool is_finish(list<int> t) {
  int a = 0;
  for (list<int>::iterator it = t.begin(); it != t.end(); it++) {
    if (*it != ++a)
      return false;
  }
  return true;
}

int main() {
  int n;
  while (cin >> n, n) {
    list<int> block;
    int a;
    for (int i = 0; i < n; i++) {
      cin >> a;
      block.push_back(a);
    }

    int ans = 0;
    while (!is_finish(block)) {
      if (ans > 10000)
        break;
      int cnt = 0;

      for (list<int>::iterator it = block.begin(); it != block.end(); it++) {
        (*(it))--;
        cnt++;
      }
      block.push_back(cnt);

      for (list<int>::iterator it = block.begin(); it != block.end(); it++) {
        if (*(it) == 0)
          block.erase(it);
      }
      ans++;
    }
    if (ans > 10000)
      cout << -1 << endl;
    else
      cout << ans << endl;
    block.clear();
  }
  return 0;
}
Problem p00262 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

int main() {
  int i, j, n, m, s, p, d[6000];
  while (cin >> n && n > 0) {
    s = p = 0;
    for (i = 0; i < n; i++) {
      cin >> d[i];
      s += d[i];
    }
    for (i = 1, m = 0; i <= 100; i++) {
      m += i;
      if (s == m)
        break;
    }
    if (i < 101)
      m = i;
    else {
      cout << -1 << endl;
      continue;
    }
    for (i = 0; i <= 10000; i++) {
      if (m == n && d[0] == 1 && d[m - 1] == m) {
        for (j = 0; j < m; j++)
          if (d[j] != j + 1)
            j = 9999;
        if (j == m)
          break;
      }
      for (j = 0; j < n; j++)
        d[j]--;
      for (j = 0, p = 0; j < n; j++)
        if (d[j] > 0)
          d[p++] = d[j];
      d[p] = n;
      n = p + 1;
    }
    if (i > 10000)
      cout << -1 << endl;
    else
      cout << i << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int i, j, n, m, s, p, d[100];
  while (cin >> n && n > 0) {
    s = p = 0;
    for (i = 0; i < n; i++) {
      cin >> d[i];
      s += d[i];
    }
    for (i = 1, m = 0; i <= 100; i++) {
      m += i;
      if (s == m)
        break;
    }
    if (i < 101)
      m = i;
    else {
      cout << -1 << endl;
      continue;
    }
    for (i = 0; i <= 10000; i++) {
      if (m == n && d[0] == 1 && d[m - 1] == m) {
        for (j = 0; j < m; j++)
          if (d[j] != j + 1)
            j = 9999;
        if (j == m)
          break;
      }
      for (j = 0; j < n; j++)
        d[j]--;
      for (j = 0, p = 0; j < n; j++)
        if (d[j] > 0)
          d[p++] = d[j];
      d[p] = n;
      n = p + 1;
    }
    if (i > 10000)
      cout << -1 << endl;
    else
      cout << i << endl;
  }
  return 0;
}
Problem p00262 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
bool check(vector<int> &B) {
  for (int i = 0; i < B.size(); i++) {
    if (B[i] != i + 1)
      return 0;
  }
  return 1;
}
int main() {
  int n;
  vector<int> T;
  for (int i = 0; i < 200; i++)
    T.push_back(i * (i + 1) / 2);
  while (cin >> n, n) {
    vector<int> B;
    int cnt = 0;
    int temp;
    for (int i = 0; i < n; i++) {
      cin >> temp;
      cnt += temp;
      B.push_back(temp);
    }
    int ans = -1;
    if (binary_search(T.begin(), T.end(), cnt)) {
      for (n = 0; n <= 10000; n++) {
        if (check(B)) {
          ans = n;
          break;
        } else {
          int a = B.size();
          for (int i = 0; i < a; i++) {
            B[i]--;
          }
          B.erase(remove(B.begin(), B.end(), 0), B.end());
          B.push_back(a);
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: -6
double free or corruption (out)


Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
bool check(vector<int> &B) {
  if (B.size() == 1)
    return 0;
  for (int i = 1; i < B.size(); i++) {
    if (B[i - 1] + 1 != B[i])
      return 0;
  }
  return 1;
}
int main() {
  int n;
  vector<int> T;
  for (int i = 0; i < 200; i++)
    T.push_back(i * (i + 1) / 2);
  while (cin >> n, n) {
    vector<int> B;
    int cnt = 0;
    int temp;
    for (int i = 0; i < n; i++) {
      cin >> temp;
      cnt += temp;
      B.push_back(temp);
    }
    int ans = -1;
    if (binary_search(T.begin(), T.end(), cnt)) {
      for (n = 0; n <= 10000; n++) {
        if (check(B)) {
          ans = n;
          break;
        } else {
          int a = B.size();
          vector<int>::iterator it = B.begin();
          for (int i = 0; i < a; i++) {
            B[i]--;
          }
          B.push_back(a);
          while (a--) {
            if ((*it) == 0) {
              it = B.erase(it);
              // it--;
            } else
              it++;
          }
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00262 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int blocks[1000001], n;

void update() {
  for (int i = 0; i < n; i++)
    blocks[i]--;
  blocks[n++] = n;
  int m = 0;
  for (int i = 0; i < n; i++) {
    if (blocks[i] == 0) {
      m++;
    } else
      blocks[i - m] = blocks[i];
  }
  n -= m;
}

bool check() {
  for (int i = 0; i < n; i++) {
    if (blocks[i] != i + 1)
      return false;
  }
  return true;
}

int main() {
  while (true) {
    cin >> n;
    if (!n)
      break;
    for (int i = 0; i < n; i++)
      cin >> blocks[i];
    for (int i = 0; i <= 10000; i++) {
      if (check()) {
        cout << i << endl;
        goto success;
      }
      update();
    }
    cout << -1 << endl;
  success:;
  }
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int blocks[101], n;

void update() {
  for (int i = 0; i < n; i++)
    blocks[i]--;
  blocks[n++] = n;
  int m = 0;
  for (int i = 0; i < n; i++) {
    if (blocks[i] == 0) {
      m++;
    } else
      blocks[i - m] = blocks[i];
  }
  n -= m;
}

bool check() {
  for (int i = 0; i < n; i++) {
    if (blocks[i] != i + 1)
      return false;
  }
  return true;
}

int main() {
  while (true) {
    cin >> n;
    if (!n)
      break;
    for (int i = 0; i < n; i++)
      cin >> blocks[i];
    for (int i = 0; i <= 10000; i++) {
      if (check()) {
        cout << i << endl;
        goto success;
      }
      update();
    }
    cout << -1 << endl;
  success:;
  }
}
Problem p00262 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define SMIN 3
#define SMAX 1000000
#define NMIN 1
#define NMAX 100
#define BMIN 1
#define BMAX 10000
#define LIM 10000
#define TCASE 20

bool valid[SMAX + 1];

bool check(vector<int> v) {
  if (v[0] != 1)
    return false;
  for (int i = 1; i < v.size(); i++) {
    if (v[i - 1] + 1 != v[i])
      return false;
  }
  return true;
}

int simulate(vector<int> v, int sum) {
  assert(SMIN <= sum && sum <= SMAX);
  // if ( !valid[sum]) return -1;
  int cnt = 0;
  while (1) {
    if (check(v))
      return cnt;
    int r = v.size();
    for (int i = 0; i < v.size(); i++)
      v[i]--;
    vector<int> nv;
    for (int i = 0; i < v.size(); i++) {
      if (v[i])
        nv.push_back(v[i]);
    }
    v = nv;
    v.push_back(r);
    cnt++;
    if (cnt > LIM)
      return cnt;
  }
}

main() {
  for (int i = 0; i <= SMAX; i++)
    valid[i] = false;
  int cur = 3, d = 3;
  while (cur <= SMAX) {
    valid[cur] = true;
    cur += d;
    d++;
  }

  int n;
  int tcase = 0;
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    tcase++;
    assert(NMIN <= n && n <= NMAX);
    vector<int> v;
    int x;
    int sum = 0;
    for (int i = 0; i < n; i++) {
      cin >> x;
      assert(BMIN <= x && x <= BMAX);
      v.push_back(x);
      sum += x;
    }
    int ans = simulate(v, sum);
    if (ans > 10000)
      cout << -1 << endl;
    else
      cout << ans << endl;
  }
  assert(tcase <= TCASE);
}

Error: 1

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define SMIN 3
#define SMAX 1000000
#define NMIN 1
#define NMAX 100
#define BMIN 1
#define BMAX 10000
#define LIM 10000
#define TCASE 20

bool valid[SMAX + 1];

bool check(vector<int> v) {
  if (v[0] != 1)
    return false;
  for (int i = 1; i < v.size(); i++) {
    if (v[i - 1] + 1 != v[i])
      return false;
  }
  return true;
}

int simulate(vector<int> v, int sum) {
  int cnt = 0;
  while (1) {
    if (check(v))
      return cnt;
    int r = v.size();
    for (int i = 0; i < v.size(); i++)
      v[i]--;
    vector<int> nv;
    for (int i = 0; i < v.size(); i++) {
      if (v[i])
        nv.push_back(v[i]);
    }
    v = nv;
    v.push_back(r);
    cnt++;
    if (cnt > LIM)
      return cnt;
  }
}

int main() {
  for (int i = 0; i <= SMAX; i++)
    valid[i] = false;
  int cur = 3, d = 3;
  while (cur <= SMAX) {
    valid[cur] = true;
    cur += d;
    d++;
  }

  int n;
  int tcase = 0;
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    tcase++;
    assert(NMIN <= n && n <= NMAX);
    vector<int> v;
    int x;
    int sum = 0;
    for (int i = 0; i < n; i++) {
      cin >> x;
      v.push_back(x);
      sum += x;
    }
    int ans = simulate(v, sum);
    if (ans > 10000)
      cout << -1 << endl;
    else
      cout << ans << endl;
  }
  return 1;
}
Problem p00263 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
string htox() {}

int main() {
  int num;
  cin >> num;
  for (int k = 0; k < num; k++) {
    string N;
    bitset<32> b;
    cin >> N;
    for (int i = 0; i < 8; i++) {
      int n;
      if (N[i] >= 'a')
        n = N[i] - 'a' + 10;
      else
        n = N[i] - '0';
      for (int j = 0; j < 4; j++)
        b.set(31 - (i * 4 + j), n & (int)pow(2, 3 - j));
    }
    if (b[31])
      cout << '-';
    long long int r = 0;
    for (int i = 7; i < 31; i++)
      if (b[i])
        r += powl(2, i - 7);
    cout << r;
    r = 0;
    for (int i = 0; i <= 6; i++)
      if (b[i])
        r += pow(0.5, 7 - i) * pow(10, 10);
    int j = 9;
    cout << '.';
    if (r != 0)
      while (r < pow(10, j)) {
        j--;
        cout << 0;
      }
    while (r % 10 == 0 && r != 0)
      r /= 10;
    cout << r;
    cout << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
string htox() {}

int main() {
  int num;
  cin >> num;
  for (int k = 0; k < num; k++) {
    string N;
    bitset<32> b;
    cin >> N;
    for (int i = 0; i < 8; i++) {
      int n;
      if (N[i] >= 'a')
        n = N[i] - 'a' + 10;
      else
        n = N[i] - '0';
      for (int j = 0; j < 4; j++)
        b.set(31 - (i * 4 + j), n & (int)pow(2, 3 - j));
    }
    if (b[31])
      cout << '-';
    long long int r = 0;
    for (int i = 7; i < 31; i++)
      if (b[i])
        r += pow(2, i - 7);
    cout << r;
    r = 0;
    for (int i = 0; i <= 6; i++)
      if (b[i])
        r += pow(5, 7 - i) * pow(10, i);
    while (r % 10 == 0)
      r /= 10;
    cout << '.' << r << endl;
  }
  return 0;
}