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

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

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FORR(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)

typedef long long ll;

int n;
int d[1252];
string S;

int main() {
  cin >> n;
  REP(i, n) cin >> d[i];
  REP(i, n) S += string(1, '0' + d[i]);
  int it = 0;
  while (true) {
    string s = to_string(it);
    bool found = false;
    REP(i, S.size() - s.size() + 1) {
      if (S.substr(i, s.size()) == s) {
        found = true;
        break;
      }
    }
    if (!found)
      break;
    it++;
  }
  cout << it << endl;
  return 0;
}

Error: MLE

Fixed submission:

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

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FORR(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)

typedef long long ll;

int n;
int d[1252];

int main() {
  cin >> n;
  REP(i, n) cin >> d[i];
  unordered_set<string> S;
  REP(i, n) {
    if (d[i] == 0) {
      S.insert("0");
      continue;
    }
    string s;
    FOR(j, i, n) {
      s += string(1, '0' + d[j]);
      S.insert(s);
    }
  }
  int it = 0;
  while (true) {
    string s = to_string(it);
    if (!S.count(s))
      break;
    it++;
  }
  cout << it << endl;
  return 0;
}
Problem p00935 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
// typedef tuple<int, int, int> T;
#define FOR(i, s, x) for (int i = s; i < (int)(x); i++)
#define REP(i, x) FOR(i, 0, x)
#define ALL(c) c.begin(), c.end()
#define DUMP(x) cerr << #x << " = " << (x) << endl

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N;
  cin >> N;
  vector<int> num(N);
  REP(i, N) cin >> num[i];

  set<string> num_set;
  REP(i, N) {
    string t;
    for (int j = i; j < N; j++) {
      if (j - i + 1 > 6)
        break;
      t.push_back(num[j] + '0');
      num_set.insert(t);
    }
  }

  REP(i, 1e6) {
    if (num_set.find(to_string(i)) == num_set.end()) {
      cout << i << endl;
      break;
    }
  }
  return 0;
}

Error: MLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
// typedef tuple<int, int, int> T;
#define FOR(i, s, x) for (int i = s; i < (int)(x); i++)
#define REP(i, x) FOR(i, 0, x)
#define ALL(c) c.begin(), c.end()
#define DUMP(x) cerr << #x << " = " << (x) << endl

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N;
  cin >> N;
  vector<int> num(N);
  REP(i, N) cin >> num[i];

  set<string> num_set;
  REP(i, N) {
    string t;
    for (int j = i; j < N; j++) {
      t.push_back(num[j] + '0');
      num_set.insert(t);
    }
  }

  REP(i, 1e6) {
    if (num_set.find(to_string(i)) == num_set.end()) {
      cout << i << endl;
      break;
    }
  }
  return 0;
}
Problem p00935 (C++) — buggy submission, verdict: Runtime Error


#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i, n) for (i = 0; i < n; i++)
#define loop(i, a, n) for (i = a; i < n; i++)
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)

typedef vector<int> vi;
typedef pair<int, int> pii;

int main(void) {
  int i, j;
  int n;
  cin >> n;
  vi d(n);
  rep(i, n) cin >> d[i];
  int m = 1000000;
  vector<bool> v(m, false);
  rep(i, n) {
    ll tmp = 0;
    for (j = i; j < n; j++) {
      tmp *= 10;
      tmp += d[j];
      if (tmp >= m)
        break;
      v[tmp] = true;
    }
  }
  rep(i, m) if (v[i] == 0) {
    cout << i << endl;
    return 0;
  }
}

Error: -6
double free or corruption (out)


Fixed submission:


#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i, n) for (i = 0; i < n; i++)
#define loop(i, a, n) for (i = a; i < n; i++)
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)

typedef vector<int> vi;
typedef pair<int, int> pii;

int main(void) {
  int i, j;
  int n, m;
  while (1) {
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    vector<bool> v(n, false);
    pair<int, pii> p[20000];
    rep(i, m) {
      cin >> p[i].first >> p[i].second.first >> p[i].second.second;
      p[i].second.first--;
      p[i].second.second--;
    }
    sort(p, p + m);
    v[0] = true;
    rep(i, m) if (v[p[i].second.first]) v[p[i].second.second] = true;
    int ans = 0;
    rep(i, n) if (v[i]) ans++;
    cout << ans << endl;
  }
}
Problem p00935 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(n) begin(n), end(n)

int a[1010];
int n;

string solve() {
  set<string> S;
  for (int i = 0; i < n; i++) {
    string cur;
    for (int j = i; j < n; j++) {
      cur += (char)(a[j] + '0');
      if (cur.size() > 10)
        continue;
      S.insert(cur);
    }
  }
  for (int i = 0; i < 1e9; i++) {
    string s = to_string(i);
    if (S.find(s) != S.end())
      continue;
    return s;
  }
  return "";
}

int main() {
  while (cin >> n) {
    rep(i, n) cin >> a[i];
    cout << solve() << endl;
  }
}

Error: MLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(n) begin(n), end(n)

int a[1010];
int n;

string solve() {
  set<string> S;
  for (int i = 0; i < n; i++) {
    string cur;
    for (int j = i; j < n; j++) {
      cur += (char)(a[j] + '0');
      S.insert(cur);
    }
  }
  for (int i = 0; i < 1e9; i++) {
    string s = to_string(i);
    if (S.find(s) != S.end())
      continue;
    return s;
  }
  return "";
}

int main() {
  while (cin >> n) {
    rep(i, n) cin >> a[i];
    cout << solve() << endl;
  }
}
Problem p00935 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <queue>
#include <string>
using namespace std;
long long a[10005], n, m, k, ans = 0, i, r, l, j, p = 0, b[10005];
int main() {
  // freopen(".in","r",stdin);
  // freopen(".out","w",stdout);
  cin >> n;
  for (i = 1; i <= n; i++)
    cin >> a[i];
  for (i = 1; i <= 4 && i <= n; i++) {
    for (l = 1; l <= n - i + 1; l++) {
      if (a[l] != 0 || i == 1) {
        for (j = l; j <= l + i - 1; j++)
          p = p * 10 + a[j];
        b[p] = 1;
        p = 0;
      }
    }
  }
  for (i = 0; i <= 10000; i++)
    if (b[i] == 0) {
      cout << i << endl;
      return 0;
    }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
const int N = 250005;
using namespace std;
int main() {
  ll ans[N], b[1005] = {0};
  int n, a, m, t = 0, tot = 0, q[10] = {0};
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a);
    if (q[a] == 0) {
      tot++;
      ans[tot] = a;
      q[a] = 1;
    }
    b[i] = a;
    m = a;
    for (int j = 1; j <= i - 1; j++) {
      b[j] *= 10;
      if (b[j] == 0)
        continue;
      a = m + b[j];
      if (a > 0) {
        tot++;
        ans[tot] = a;
      }
      b[j] += m;
    }
  }
  if (q[0] == 0) {
    printf("0\\n");
    return 0;
  }
  ans[0] = -1;
  sort(ans + 1, ans + tot + 1);
  for (int i = 0; i <= tot - 1; i++) {
    if (ans[i] + 1 < ans[i + 1]) {
      printf("%lld\\n", ans[i] + 1);
      t = 1;
      return 0;
    }
  }
  if (t == 0)
    printf("%lld\\n", ans[tot] + 1);
}
Problem p00935 (C++) — buggy submission, verdict: Runtime Error

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

int n;
int d[1000];
bool exist[1000001];

int getNum(int l, int r) {
  int ret = 0;
  for (int i = l; i <= r; i++) {
    ret *= 10;
    ret += d[i];
  }
  return ret;
}

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

  for (i = 0; i < n; i++) {
    for (j = i; j < min(n, i + 6); j++) {
      exist[getNum(i, j)] = true;
    }
  }

  for (i = 0; i < n * n; i++) {
    if (!exist[i]) {
      cout << i << endl;
      break;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int n;
int d[1000];
bool exist[1000001];

int getNum(int l, int r) {
  int ret = 0;
  for (int i = l; i <= r; i++) {
    ret *= 10;
    ret += d[i];
  }
  return ret;
}

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

  for (i = 0; i < n; i++) {
    for (j = i; j < i + 6; j++) {
      exist[getNum(i, j)] = true;
    }
  }

  for (i = 0; i < n * n; i++) {
    if (!exist[i]) {
      cout << i << endl;
      break;
    }
  }
  return 0;
}
Problem p00935 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n;
  cin >> n;
  vector<int> appear(10000, 0);

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

  for (int i = 0; i < n; i++) {
    int sum = 0;
    for (int j = 0; j < 4; j++) {
      if (i + j >= n)
        break;
      sum = sum * 10 + d[i + j];
      appear[sum] = 1;
    }
  }

  for (int i = 0; i < 10000; i++) {
    if (appear[i] == 0) {
      cout << i << endl;
      break;
    }
  }
}


Error: -6
free(): invalid pointer


Fixed submission:

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

int main() {
  int n;
  cin >> n;
  vector<int> appear(10 * n, 0);

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

  for (int i = 0; i < n; i++) {
    int sum = 0;
    for (int j = 0; j < 4; j++) {
      if (i + j >= n)
        break;
      sum = sum * 10 + (int)(d[i + j]);
      appear[sum] = 1;
    }
  }

  for (int i = 1; i < 10 * n; i++) {
    if (appear[i] == 0) {
      cout << i << endl;
      break;
    }
  }
}
Problem p00935 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int n;
vector<int> v;

int solve() {
  bool f[10000];
  fill(f, f + 10000, false);

  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < (int)v.size() - i + 1; j++) {
      int num = 0;
      for (int k = j; k < j + i; k++) {
        num *= 10;
        num += v[k];
        if (num >= 10000)
          break;
      }
      if (num >= 10000)
        continue;
      f[num] = true;
    }
  }

  for (int i = 0; i < 10000; i++) {
    if (!f[i])
      return i;
  }
  return 10000;
}

int main() {
  while (cin >> n) {
    v.clear();
    for (int i = 0; i < n; i++) {
      int x;
      cin >> x;
      v.push_back(x);
    }
    cout << solve() << endl;
  }
}

Error: TLE

Fixed submission:

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

int n;
vector<int> v;

int solve() {
  bool f[10000];
  fill(f, f + 10000, false);

  for (int i = 1; i <= 3; i++) {
    for (int j = 0; j < v.size() - i + 1; j++) {
      int num = 0;
      for (int k = j; k < j + i; k++) {
        num *= 10;
        num += v[k];
      }
      while (num >= 10000)
        ;
      f[num] = true;
    }
  }

  for (int i = 0; i < 10000; i++) {
    if (!f[i])
      return i;
  }
  return 10000;
}

int main() {
  while (cin >> n) {
    v.clear();
    for (int i = 0; i < n; i++) {
      int x;
      cin >> x;
      v.push_back(x);
    }
    cout << solve() << endl;
  }
}
Problem p00935 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define r(i, n) for (int i = 0; i < n; i++)
using namespace std;
bool p[10000];
int main() {
  int n, c;
  cin >> n;
  int a[n];
  r(i, n) cin >> a[i];
  r(i, n) p[a[i]] = true;
  if (n > 1)
    r(i, n - 1) {
      int s = a[i] * 10 + a[i + 1];
      p[s] = true;
    }
  if (n > 2)
    r(i, n - 2) {
      int s = a[i] * 100 + a[i + 1] * 10 + a[i + 2];
      p[s] = true;
    }
  if (n > 3)
    r(i, n - 3) {
      int s = a[i] * 1000 + a[i + 1] * 100 + a[i + 2] * 10 + a[i + 3];
      p[s] = true;
    }
  c = 0;
  while (p[c])
    c++;
  cout << c << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define r(i, n) for (int i = 0; i < n; i++)
using namespace std;
bool p[1001];
int main() {
  int n, c;
  cin >> n;
  int a[n];
  r(i, n) cin >> a[i];
  r(i, n) p[a[i]] = true;
  if (n > 1)
    r(i, n - 1) {
      int s = a[i] * 10 + a[i + 1];
      p[s] = true;
    }
  if (n > 2)
    r(i, n - 2) {
      int s = a[i] * 100 + a[i + 1] * 10 + a[i + 2];
      p[s] = true;
    }
  if (n > 3)
    r(i, n - 3) {
      int s = a[i] * 1000 + a[i + 1] * 100 + a[i + 2] * 10 + a[i + 3];
      p[s] = true;
    }
  c = 0;
  while (p[c])
    c++;
  cout << c << endl;
}
Problem p00936 (C++) — buggy submission, verdict: Runtime Error

#include <cassert>
#include <cmath>
#include <iostream>
#define rep(i, n) for (int i = 0; i < n; ++i)
using namespace std;

double r[1010], x[1010];

const double eps = 1e-5;
const double inf = 1e9;

bool cross(int m, double cx, double cy) {
  rep(i, m) {
    double dd = 0.0;
    dd += 1.0 * (x[i] - cx) * (x[i] - cx);
    dd += 1.0 * (r[i] - cy) * (r[i] - cy);
    double rr = 1.0 * (r[i] + r[m]) * (r[i] + r[m]);
    // cerr << rr << " " << dd << endl;
    if (rr > dd + eps)
      return true;
  }
  return false;
}

int main(void) {
  int n;
  cin >> n;
  rep(i, n) cin >> r[i];
  rep(i, n) x[i] = inf;

  rep(i, n) {
    for (int j = -1; j < i; ++j) {
      double cx = r[i];
      if (j >= 0) {
        double d = 1.0 * (r[i] + r[j]) * (r[i] + r[j]);
        d -= 1.0 * (r[i] - r[j]) * (r[i] - r[j]);
        cx = x[j] + sqrt(d);
      }
      if (cx < r[i])
        continue;
      if (i > 0 && x[i - 1] >= cx)
        continue;
      if (cross(i, cx, r[i]))
        continue;
      x[i] = min(x[i], cx);
    }
    // cerr << i << " " << x[i] << " " << r[i] << endl;
  }

  double ans = 0.0;
  rep(i, n) ans = max(ans, x[i] + r[i]);
  cout.precision(20);
  assert(ans < inf);
  cout << fixed << ans << endl;
  return 0;
}

Error: WA

Fixed submission:

#include <cassert>
#include <cmath>
#include <iostream>
#define rep(i, n) for (int i = 0; i < n; ++i)
using namespace std;

double r[1010], x[1010];

const double eps = 1e-11;
const double inf = 1e9;

bool cross(int m, double cx, double cy) {
  rep(i, m) {
    double dd = 0.0;
    dd += 1.0 * (x[i] - cx) * (x[i] - cx);
    dd += 1.0 * (r[i] - cy) * (r[i] - cy);
    double rr = 1.0 * (r[i] + r[m]) * (r[i] + r[m]);
    // cerr << rr << " " << dd << endl;
    if (rr > dd + eps)
      return true;
  }
  return false;
}

int main(void) {
  int n;
  cin >> n;
  rep(i, n) cin >> r[i];
  rep(i, n) x[i] = inf;

  rep(i, n) {
    for (int j = -1; j < i; ++j) {
      double cx = r[i];
      if (j >= 0) {
        double d = 1.0 * (r[i] + r[j]) * (r[i] + r[j]);
        d -= 1.0 * (r[i] - r[j]) * (r[i] - r[j]);
        cx = x[j] + sqrt(d);
      }
      if (cx < r[i])
        continue;
      if (i > 0 && x[i - 1] >= cx)
        continue;
      if (cross(i, cx, r[i]))
        continue;
      x[i] = min(x[i], cx);
    }
    // cerr << i << " " << x[i] << " " << r[i] << endl;
  }

  double ans = 0.0;
  rep(i, n) ans = max(ans, x[i] + r[i]);
  cout.precision(20);
  assert(ans < inf);
  cout << fixed << ans << endl;
  return 0;
}
Problem p00936 (C++) — buggy submission, verdict: Runtime Error

#include <iomanip>
#include <iostream>
using namespace std;
#define MAX_N 100000
long double x[MAX_N];
long double y[MAX_N];
int N;
bool solve(long double a, int b) {
  for (int i = 0; i < b; i++) {
    long double X1 = a, Y1 = x[b];
    long double X2 = y[i], Y2 = x[i];
    long double dist = (X2 - X1) * (X2 - X1) + (Y2 - Y1) * (Y2 - Y1);
    if (a < y[i]) {
      return false;
    }
    if (dist < (x[i] + x[b]) * (x[i] + x[b])) {
      return false;
    }
  }
  if (x[b] > a) {
    return false;
  }
  return true;
}
int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> x[i];
    if (i == 0) {
      y[i] = x[i];
    } else {
      long double L = 0, R = 1000000000.00, M;
      for (int k = 0; k < 1500; k++) {
        M = (L + R) / 2;
        bool a1 = solve(M, i);
        if (a1 == true) {
          R = M;
        } else {
          L = M;
        }
      }
      y[i] = M;
    }
  }
  long double minx = 0;
  for (int i = 0; i < N; i++) {
    long double dis = y[i] + x[i];
    if (dis > minx) {
      minx = dis;
    }
  }
  cout << fixed << setprecision(14) << minx << endl;
  return 0;
}

Error: -11

Fixed submission:

#include <iomanip>
#include <iostream>
using namespace std;
#define MAX_N 100000
long double x[MAX_N];
long double y[MAX_N];
int N;
bool solve(long double a, int b) {
  for (int i = 0; i < b; i++) {
    long double X1 = a, Y1 = x[b];
    long double X2 = y[i], Y2 = x[i];
    long double dist = (X2 - X1) * (X2 - X1) + (Y2 - Y1) * (Y2 - Y1);
    if (dist < (x[i] + x[b]) * (x[i] + x[b])) {
      return false;
    }
  }
  return true;
}
int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> x[i];
    if (i == 0) {
      y[i] = x[i];
    } else {
      long double L = 0, R = 1000000000.00, M;
      for (int k = 0; k < 1000; k++) {
        M = (L + R) / 2;
        bool a1 = solve(M, i);
        if (a1 == true) {
          R = M;
        } else {
          L = M;
        }
      }
      y[i] = M;
    }
  }
  long double minx = 0;
  for (int i = 0; i < N; i++) {
    long double dis = y[i] + x[i];
    if (dis > minx) {
      minx = dis;
    }
  }
  cout << fixed << setprecision(5141919) << minx << endl;
  return 0;
}
Problem p00936 (C++) — buggy submission, verdict: Runtime Error


#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using LL = long long;

double cost(double r1, double r2) {
  return sqrt((r1 + r2) * (r1 + r2) - (r1 - r2) * (r1 - r2));
}

int main(void) {
  int N;
  vector<int> r;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    int rr;
    cin >> rr;
    r.push_back(rr);
  }

  vector<double> place(1, 0.);
  for (int i = 1; i < N; ++i) {
    double big = 0;
    for (int j = 0; j < i; ++j) {
      big = max(big, place[j] + cost(r[j], r[i]));
    }
    place.push_back(big);
  }
  double head = 0, tail = 0;
  for (int i = 0; i < place.size(); ++i) {
    head = min(head, place[i] - r[i]);
    tail = max(tail, place[i] + r[i]);
  }
  cout.precision(15);
  cout << tail - head << endl;
  return 0;
}

Error: -6
double free or corruption (out)


Fixed submission:


#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using LL = long long;

double cost(double r1, double r2) {
  return sqrt((r1 + r2) * (r1 + r2) - (r1 - r2) * (r1 - r2));
}

int main(void) {
  int N;
  vector<int> r;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    int rr;
    cin >> rr;
    r.push_back(rr);
    while (r.size() <= 1) {
      int sml = min(r[r.size() - 2], r.back());
      int big = max(r[r.size() - 2], r.back());
      if (big * (sqrt(2) - 1) / 2. > sml) {
        if (r[r.size() - 2] < r.back()) {
          r.erase(r.begin() + r.size() - 2);
        } else {
          r.pop_back();
        }
      } else {
        break;
      }
    }
  }
  double ans = r.front() + r.back();
  for (int i = 1; i < r.size(); ++i) {
    ans += cost(r[i - 1], r[i]);
  }
  cout.precision(15);
  cout << ans << endl;
  return 0;
}
Problem p00936 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define DEBUG(x) cerr << #x << " = " << x << endl
#define int long long
signed main() {
  int N;
  cin >> N;
  vector<int> R(N);
  REP(i, N) cin >> R[i];
  // double ans = 0.0;
  // ans += R[0] + R[N - 1];
  // for(int i = 0; i < N - 1; ++i) {
  //   int mx = max(R[i], R[i + 1]);
  //   int mn = min(R[i], R[i + 1]);
  //   ans += sqrt(max<double>(0.0, (R[i] + R[i + 1]) * (R[i] + R[i + 1]) - (mx
  //   - mn) * (mx - mn)));
  // }
  // cout << ans << endl;
  vector<double> pos(N);
  double ans = R[0] * 2;
  pos[0] = R[0];
  for (int i = 1; i < N; ++i) {
    pos[i] = R[i];
    REP(j, i) {
      int mx = max(R[i], R[j]);
      int mn = min(R[i], R[j]);
      double update =
          pos[j] + sqrt(max<double>(0.0, (R[i] + R[j]) * (R[i] + R[j]) -
                                             (mx - mn) * (mx - mn)));
      // DEBUG(update);
      pos[i] = max(pos[i], update);
    }
    ans = max(ans, pos[i] + R[i]);
    // cerr << "pos[" << i << "] = " << pos[i] << endl;
  }
  cout.setf(ios::fixed);
  cout.precision(10);
  cout << ans << endl;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define DEBUG(x) cerr << #x << " = " << x << endl
#define int long long
signed main() {
  int N;
  cin >> N;
  vector<int> R(N);
  REP(i, N) cin >> R[i];
  // double ans = 0.0;
  // ans += R[0] + R[N - 1];
  // for(int i = 0; i < N - 1; ++i) {
  //   int mx = max(R[i], R[i + 1]);
  //   int mn = min(R[i], R[i + 1]);
  //   ans += sqrt(max<double>(0.0, (R[i] + R[i + 1]) * (R[i] + R[i + 1]) - (mx
  //   - mn) * (mx - mn)));
  // }
  // cout << ans << endl;
  vector<double> pos(N);
  double ans = R[0] * 2;
  pos[0] = R[0];
  for (int i = 1; i < N; ++i) {
    pos[i] = R[i];
    REP(j, i) {
      int mx = max(R[i], R[j]);
      int mn = min(R[i], R[j]);
      double update =
          pos[j] + sqrt(max<double>(0.0, (R[i] + R[j]) * (R[i] + R[j]) -
                                             (mx - mn) * (mx - mn)));
      // DEBUG(update);
      pos[i] = max(pos[i], update);
    }
    ans = max(ans, pos[i] + R[i]);
    cerr << "pos[" << i << "] = " << pos[i] << endl;
  }
  cout.setf(ios::fixed);
  cout.precision(10);
  cout << ans << endl;
}