Problem p02303 (C++) — buggy submission, verdict: Runtime Error

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1 << 30
#define LINF 1LL << 60

typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-9, pi = acos(-1.0);
namespace std {
bool operator<(const Point &lhs, const Point &rhs) {
  if (lhs.real() < rhs.real() - eps)
    return true;
  if (lhs.real() > rhs.real() + eps)
    return false;
  return lhs.imag() < rhs.imag();
}
} // namespace std
Point input_point() {
  ld x, y;
  cin >> x >> y;
  return Point(x, y);
} // ????????\\???
bool eq(ld a, ld b) { return (abs(a - b) < eps); } // ????????????????????????
ld dot(Point a, Point b) { return real(conj(a) * b); }   // ??????
ld cross(Point a, Point b) { return imag(conj(a) * b); } // ??????

// ??´????????????
class Line {
public:
  Point a, b;
  Line() : a(Point(0, 0)), b(Point(0, 0)) {}
  Line(Point a, Point b) : a(a), b(b) {}
  Point operator[](const int _num) {
    if (_num == 0)
      return a;
    else if (_num == 1)
      return b;
    else
      assert(false);
  }
};

// ????????????
class Circle {
public:
  Point p;
  ld r;
  Circle() : p(Point(0, 0)), r(0) {}
  Circle(Point p, ld r) : p(p), r(r) {}
};

typedef vector<Point> Polygon;
/* ????????\\?????? : ????????±?????? */
bool compY(const Point &a, const Point &b) {
  return a.imag() != b.imag() ? a.imag() < b.imag() : a.real() < b.real();
}
ld ClosestPair(int l, int r, const Polygon &poly) {
  if (r - l < 2)
    return 1e16;
  int m = (l + r) / 2;
  ld res = min(ClosestPair(l, m, poly), ClosestPair(m, r, poly));
  Polygon v;
  for (int i = l; i < r; i++) {
    if (abs(poly[i].real() - poly[m].real()) < res)
      v.push_back(poly[i]);
  }

  sort(v.begin(), v.end(), compY);

  for (int i = 0; i < (int)v.size(); i++) {
    for (int j = max(0, i - 10); j < i; j++) {
      res = min(res, abs(v[i] - v[j]));
    }
  }
  return res;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  Polygon ps;
  for (int i = 0; i < n; i++)
    ps.emplace_back(input_point());
  sort(ps.begin(), ps.end());
  cout << fixed << setprecision(20) << ClosestPair(0, n, ps) << endl;
  return 0;
}

Error: WA

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1 << 30
#define LINF 1LL << 60

typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-9, pi = acos(-1.0);
namespace std {
bool operator<(const Point &lhs, const Point &rhs) {
  if (lhs.real() < rhs.real() - eps)
    return true;
  if (lhs.real() > rhs.real() + eps)
    return false;
  return lhs.imag() < rhs.imag();
}
} // namespace std
Point input_point() {
  ld x, y;
  cin >> x >> y;
  return Point(x, y);
} // ????????\\???
bool eq(ld a, ld b) { return (abs(a - b) < eps); } // ????????????????????????
ld dot(Point a, Point b) { return real(conj(a) * b); }   // ??????
ld cross(Point a, Point b) { return imag(conj(a) * b); } // ??????

// ??´????????????
class Line {
public:
  Point a, b;
  Line() : a(Point(0, 0)), b(Point(0, 0)) {}
  Line(Point a, Point b) : a(a), b(b) {}
  Point operator[](const int _num) {
    if (_num == 0)
      return a;
    else if (_num == 1)
      return b;
    else
      assert(false);
  }
};

// ????????????
class Circle {
public:
  Point p;
  ld r;
  Circle() : p(Point(0, 0)), r(0) {}
  Circle(Point p, ld r) : p(p), r(r) {}
};

typedef vector<Point> Polygon;
/* ????????\\?????? */
ld ClosestPair(int l, int r, const Polygon &poly) {
  int n = (int)poly.size();
  if (n == 2)
    return abs(poly[l] - poly[l + 1]);
  if (n == 3)
    return min({abs(poly[l] - poly[l + 1]), abs(poly[l] - poly[l + 2]),
                abs(poly[l + 1] - poly[l + 2])});

  int m = l + (r - l) / 2;
  // ????????±??????
  ld d = min(ClosestPair(l, m, poly), ClosestPair(m + 1, r, poly));

  Polygon v;
  for (int i = l; i <= r; i++) {
    if (abs(poly[i].real() - poly[m].real()) < d) {
      v.emplace_back(Point(poly[i].imag(), poly[i].real()));
    }
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < (int)v.size(); i++) {
    for (int j = i + 1; j < (int)v.size(); j++) {
      if (abs(v[i].real() - v[j].real()) > d)
        break;
      d = min(d, abs(v[i] - v[j]));
    }
  }
  return d;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  Polygon ps;
  for (int i = 0; i < n; i++)
    ps.emplace_back(input_point());
  cout << fixed << setprecision(10) << ClosestPair(0, (int)ps.size() - 1, ps)
       << endl;
  return 0;
}