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

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>
#define curr(P, i) P[(i) % P.size()]
#define next(P, i) P[(i + 1) % P.size()]
#define prev(P, i) P[(i + P.size() - 1) % P.size()]

using namespace std;

double EPS = 1e-10;
const double PI = acos(-1);

double add(double a, double b) {
  if (abs(a + b) < EPS * (abs(a) + abs(b)))
    return 0;
  return a + b;
}

struct point {
  double x, y;
  point() {}
  point(double x, double y) : x(x), y(y) {}

  point operator+(point p) { return point(add(x, p.x), add(y, p.y)); }

  point operator-(point p) { return point(add(x, -p.x), add(y, -p.y)); }

  point operator*(double d) { return point(x * d, y * d); }
};

double areaPol(vector<point> t) {
  double area = 0;
  for (int i = 0; i < t.size(); i++)
    area += (curr(t, i).x - next(t, i).x) * (curr(t, i).y + next(t, i).y);

  return abs(area) / 2.0;
}

int main(void) {
  int n;
  cin >> n;
  vector<point> pol(n);

  for (int i = 0; i < n; i++)
    cin >> pol[i].x >> pol[i].y;

  printf("%.1f\\n", areaPol(pol));

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>
#define curr(P, i) P[(i) % P.size()]
#define next(P, i) P[(i + 1) % P.size()]

using namespace std;

struct point {
  double x, y;
};

double areaPol(vector<point> t) {
  double area = 0;
  for (int i = 0; i < t.size(); i++)
    area += (curr(t, i).x - next(t, i).x) * (curr(t, i).y + next(t, i).y);

  return abs(area) / 2.0;
}

int main(void) {
  int n, turn = 1;
  point p;
  vector<point> t;

  while (cin >> n, n) {
    t.clear();
    for (int i = 0; i < n; i++) {
      cin >> p.x >> p.y;
      t.push_back(p);
    }
    printf("%d %.1f\\n", turn++, areaPol(t));
  }

  return 0;
}
Problem p02300 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <complex>
#include <iostream>
#include <string>
#include <vector>
#define x real()
#define y imag()
#define px second
#define py first
using namespace std;
typedef complex<double> vectol;
typedef pair<int, int> P;
P G[100001];
vector<P> stc;

int ccw(vectol a, vectol b, vectol c) {
  vectol ab = b - a, ac = c - a;
  vectol d = ac * conj(ab);
  if (d.y > 0)
    return true;
  return false;
}

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> G[i].px >> G[i].py;
  sort(G, G + n);

  stc.push_back(G[0]), stc.push_back(G[1]);
  for (int i = 2; i < n; i++) {
    vectol av = vectol(stc[stc.size() - 2].px, stc[stc.size() - 2].py);
    vectol bv = vectol(stc[stc.size() - 1].px, stc[stc.size() - 1].py);
    vectol cv = vectol(G[i].px, G[i].py);
    if (ccw(av, bv, cv) && stc.size() != 1)
      stc.pop_back(), i--;
    else
      stc.push_back(G[i]);
  }
  for (int i = n - 2; i >= 0; i--) {
    vectol av = vectol(stc[stc.size() - 2].px, stc[stc.size() - 2].py);
    vectol bv = vectol(stc[stc.size() - 1].px, stc[stc.size() - 1].py);
    vectol cv = vectol(G[i].px, G[i].py);
    if (ccw(av, bv, cv))
      stc.pop_back(), i++;
    else
      stc.push_back(G[i]);
  }
  stc.pop_back();

  cout << stc.size() << endl;
  cout << stc[0].px << " " << stc[0].py << endl;
  for (int i = stc.size() - 1; i > 0; i--)
    cout << stc[i].px << " " << stc[i].py << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <complex>
#include <iostream>
#include <string>
#include <vector>
#define x real()
#define y imag()
#define px first
#define py second
using namespace std;
typedef complex<double> vectol;
typedef pair<int, int> P;
P G[100001];
vector<P> stc;

int ccw(vectol a, vectol b, vectol c) {
  vectol ab = b - a, ac = c - a;
  vectol d = ac * conj(ab);
  if (d.y > 0)
    return false;
  if (d.y < 0)
    return true;
  ab = ab * conj(ab);
  if (ab.x < d.x)
    return true;
  if (0 > d.x)
    return true;
  return false;
}

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> G[i].px >> G[i].py;
  sort(G, G + n);

  stc.push_back(G[0]);
  stc.push_back(G[1]);
  for (int i = 2; i < n; i++) {
    vectol av = vectol(stc[stc.size() - 2].px, stc[stc.size() - 2].py);
    vectol bv = vectol(stc[stc.size() - 1].px, stc[stc.size() - 1].py);
    vectol cv = vectol(G[i].px, G[i].py);
    if (ccw(av, bv, cv) == false)
      stc.pop_back(), i--;
    else
      stc.push_back(G[i]);
  }

  stc.push_back(G[n - 2]);
  for (int i = n - 2; i > 0; i--) {
    vectol av = vectol(stc[stc.size() - 2].px, stc[stc.size() - 2].py);
    vectol bv = vectol(stc[stc.size() - 1].px, stc[stc.size() - 1].py);
    vectol cv = vectol(G[i].px, G[i].py);
    if (ccw(av, bv, cv) == false)
      stc.pop_back(), i--;
    else
      stc.push_back(G[i]);
  }
  cout << stc.size() << endl;
  cout << stc[0].px << " " << stc[0].py << endl;
  for (int i = stc.size() - 1; i > 0; i--)
    cout << stc[i].px << " " << stc[i].py << endl;
  return 0;
}
Problem p02300 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <complex>
#include <iostream>
#include <vector>
#define push push_back
#define sz stack.size()
#define m make_pair
#define N_MAX 100001
#define x second
#define y first
using namespace std;
typedef complex<int> point;
typedef pair<int, int> P;

bool ccw(point p0, point p1, point p2) {
  point temp;
  p1 -= p0;
  p2 -= p0;
  temp = p1;
  p1 *= conj(temp);
  p2 *= conj(temp);
  if (abs(temp) == 0)
    return true;
  p1 /= abs(temp);
  if (p2.imag() > 0)
    return false;
  if (p2.imag() < 0)
    return true;
  p2 /= abs(temp);
  return true;
}

int main() {
  int n;
  P p[N_MAX];
  vector<P> stack;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> p[i].x >> p[i].y;
  sort(p, p + n);
  stack.push(p[0]);
  stack.push(p[1]);
  for (int i = 2; i < n; i++) {
    point c = point(p[i].x, p[i].y);
    while (sz >= 2 && !ccw(point(stack[sz - 2].x, stack[sz - 2].y),
                           point(stack[sz - 1].x, stack[sz - 1].y), c))
      stack.pop_back();
    stack.push(p[i]);
  }
  for (int i = n - 2; i >= 0; i--) {
    point c = point(p[i].x, p[i].y);
    while (sz >= 2 && !ccw(point(stack[sz - 2].x, stack[sz - 2].y),
                           point(stack[sz - 1].x, stack[sz - 1].y), c))
      stack.pop_back();
    stack.push(p[i]);
  }
  stack.erase(stack.begin());
  cout << stack.size() << endl;
  for (int i = sz - 1; i >= 0; i--)
    cout << stack[i].x << ' ' << stack[i].y << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <complex>
#include <iostream>
#include <vector>
#define push push_back
#define sz stack.size()
#define m make_pair
#define N_MAX 10001
#define x second
#define y first
using namespace std;
typedef complex<int> point;
typedef pair<int, int> P;

bool ccw(point p0, point p1, point p2) {
  point temp;
  p1 -= p0;
  p2 -= p0;
  temp = p1;
  p1 *= conj(temp);
  p2 *= conj(temp);
  if (abs(temp) == 0)
    return true;
  p1 /= abs(temp);
  if (p2.imag() > 0)
    return false;
  if (p2.imag() < 0)
    return true;
  p2 /= abs(temp);
  return true;
}

int main() {
  int n;
  P p[N_MAX];
  vector<P> stack;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> p[i].x >> p[i].y;
  sort(p, p + n);
  stack.push(p[0]);
  stack.push(p[1]);
  for (int i = 2; i < n; i++) {
    point c = point(p[i].x, p[i].y);
    while (sz >= 2 && !ccw(point(stack[sz - 2].x, stack[sz - 2].y),
                           point(stack[sz - 1].x, stack[sz - 1].y), c))
      stack.pop_back();
    stack.push(p[i]);
  }
  for (int i = n - 2; i >= 0; i--) {
    point c = point(p[i].x, p[i].y);
    while (sz >= 2 && !ccw(point(stack[sz - 2].x, stack[sz - 2].y),
                           point(stack[sz - 1].x, stack[sz - 1].y), c))
      stack.pop_back();
    stack.push(p[i]);
  }
  stack.erase(stack.begin());
  cout << stack.size() << endl;
  for (int i = sz - 1; i >= 0; i--)
    cout << stack[i].x << ' ' << stack[i].y << endl;
  return 0;
}
Problem p02300 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define x second
#define y first
using namespace std;

typedef complex<double> point;
typedef pair<int, int> P;
P a[100000];
vector<int> st;
bool ccw(point a, point b, point c) {
  b -= a, c -= a;
  c *= conj(b);
  if (c.imag() <= 0)
    return true;
  return false;
}

void check(int i) {
  while ((int)st.size() >= 2) {
    int s = st[(int)st.size() - 2];
    int e = st[(int)st.size() - 1];
    point S = point(a[s].x, a[s].y);
    point E = point(a[e].x, a[e].y);
    point N = point(a[i].x, a[i].y);
    if (ccw(S, E, N))
      break;
    st.pop_back();
  }
  st.push_back(i);
}

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i].x >> a[i].y;
  sort(a, a + n);
  for (int i = 0; i < n; i++)
    check(i);
  for (int i = n - 2; i >= 0; i--)
    check(i);

  cout << (int)st.size() - 1 << endl;
  for (int i = (int)st.size() - 1; i > 0; i--)
    cout << a[st[i]].x << ' ' << a[st[i]].y << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define x second
#define y first
typedef complex<double> point;
typedef pair<int, int> P;
P a[100000];
vector<int> st;
bool ccw(point a, point b, point c) {
  b -= a, c -= a;
  c *= conj(b);
  if (c.imag() <= 0)
    return true;
  return false;
}

void check(int i) {
  int stSize = st.size();
  while (stSize >= 2) {
    int s = st[stSize - 2];
    int e = st[stSize - 1];
    point S = point(a[s].x, a[s].y);
    point E = point(a[e].x, a[e].y);
    point N = point(a[i].x, a[i].y);
    if (ccw(S, E, N))
      break;
    st.pop_back();
  }
  st.push_back(i);
}

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i].x >> a[i].y;
  sort(a, a + n);
  for (int i = 0; i < n; i++)
    check(i);
  for (int i = n - 2; i >= 0; i--)
    check(i);

  cout << (int)st.size() - 1 << endl;
  for (int i = (int)st.size() - 1; i > 0; i--)
    cout << a[st[i]].x << ' ' << a[st[i]].y << endl;
  return 0;
}
Problem p02300 (C++) — buggy submission, verdict: Runtime Error

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

class Point {
public:
  int x, y;
  Point(int a = 0, int b = 0) {
    int x = a;
    int y = b;
  };
  bool operator<(const Point &p) const {
    return y < p.y || (y == p.y && x < p.x);
  }
};

inline bool direct(Point &base, Point &a, Point &b) {
  return (a.x - base.x) * (b.y - base.y) - (a.y - base.y) * (b.x - base.x) < 0;
}

int main() {
  int n, i;
  int k = 2;
  scanf("%d", &n);
  vector<Point> P(n), H(2 * n);
  for (i = 1; i <= n; ++i) {
    scanf("%d%d", &P[i - 1].x, &P[i - 1].y);
  }
  sort(P.begin(), P.end());
  H[0] = P[0];
  H[1] = P[1];
  for (i = 0; i < n - 2; ++i) {
    while (k >= 2 && direct(H[k - 2], H[k - 1], P[i + 2]))
      k--;
    H[k++] = P[i + 2];
  }
  H[k++] = P[n - 2];
  for (i = n; i > 2; i--) {
    while (k >= 2 && direct(H[k - 2], H[k - 1], P[i - 3]))
      k--;
    H[k++] = P[i - 3];
  }
  printf("%d\\n", k - 1);
  for (i = 0; i < k - 1; ++i) {
    printf("%d %d\\n", H[i].x, H[i].y);
  }
  return 0;
}

Error: 0

Fixed submission:

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

class Point {
public:
  int x, y;
  Point(int a = 0, int b = 0) {
    int x = a;
    int y = b;
  };
  bool operator<(const Point &p) const {
    return y < p.y || (y == p.y && x < p.x);
  }
};

inline bool direct(Point &base, Point &a, Point &b) {
  return (a.x - base.x) * (b.y - base.y) - (a.y - base.y) * (b.x - base.x) < 0;
}

int main() {
  int n, i;
  int k = 2;
  scanf("%d", &n);
  vector<Point> P(n), H(n);
  for (i = 1; i <= n; ++i) {
    scanf("%d%d", &P[i - 1].x, &P[i - 1].y);
  }
  sort(P.begin(), P.end());
  H[0] = P[0];
  H[1] = P[1];
  for (i = 0; i < n - 2; ++i) {
    while (k >= 2 && direct(H[k - 2], H[k - 1], P[i + 2]))
      k--;
    H[k++] = P[i + 2];
  }
  H[k++] = P[n - 2];
  for (i = n; i > 2; i--) {
    while (k >= 2 && direct(H[k - 2], H[k - 1], P[i - 3]))
      k--;
    H[k++] = P[i - 3];
  }
  printf("%d\\n", k - 1);
  for (i = 0; i < k - 1; ++i) {
    printf("%d %d\\n", H[i].x, H[i].y);
  }
  return 0;
}
Problem p02300 (C++) — buggy submission, verdict: Time Limit Exceeded

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

class Point {
public:
  int x, y;
  Point(int a = 0, int b = 0) {
    int x = a;
    int y = b;
  };
  bool operator<(const Point &p) const {
    return y < p.y || (y == p.y && x < p.x);
  }
};

inline bool direct(Point &base, Point &a, Point &b) {
  return (a.x - base.x) * (b.y - base.y) - (a.y - base.y) * (b.x - base.x) < 0;
}

int main() {
  int n, i;
  int k = 2;
  Point *P;
  Point *H;
  scanf("%d", &n);
  P = new Point[n];
  for (i = 1; i <= n; ++i) {
    scanf("%d%d", &P[i - 1].x, &P[i - 1].y);
#if 0
        Point point = P[i - 1];
        int j;
        for (j = i; j >= 2 && point < P[j - 2]; j--) {
            P[j - 1] = P[j - 2];
        }
        P[j - 1] = point;
#endif
  }
  sort(P, P + n);
  H = new Point[2 * n];
  H[0] = P[0];
  H[1] = P[1];
  for (i = 0; i < n - 2; ++i) {
    while (k >= 2 && direct(H[k - 2], H[k - 1], P[i + 2]))
      k--;
    H[k++] = P[i + 2];
  }
  H[k++] = P[n - 2];
  for (i = n; i > 2; i--) {
    while (k >= 2 && direct(H[k - 2], H[k - 1], P[i - 3]))
      k--;
    H[k++] = P[i - 3];
  }
  printf("%d\\n", k - 1);
  for (i = 0; i < k - 1; ++i) {
    printf("%d %d\\n", H[i].x, H[i].y);
  }
  return 0;
}

Error: TLE

Fixed submission:

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

class Point {
public:
  int x, y;
  Point(int a = 0, int b = 0) {
    int x = a;
    int y = b;
  };
  bool operator<(const Point &p) const {
    return y < p.y || (y == p.y && x < p.x);
  }
};

inline bool direct(Point &base, Point &a, Point &b) {
  return (a.x - base.x) * (b.y - base.y) - (a.y - base.y) * (b.x - base.x) < 0;
}

int main() {
  int n, i;
  int k = 2;
  Point *P;
  Point *H;
  scanf("%d", &n);
  P = new Point[n];
  for (i = 1; i <= n; ++i) {
    scanf("%d%d", &P[i - 1].x, &P[i - 1].y);
    Point point = P[i - 1];
    int j;
    for (j = i; j >= 2 && point < P[j - 2]; j--) {
      P[j - 1] = P[j - 2];
    }
    P[j - 1] = point;
  }
  H = new Point[2 * n];
  H[0] = P[0];
  H[1] = P[1];
  for (i = 0; i < n - 2; ++i) {
    while (k >= 2 && direct(H[k - 2], H[k - 1], P[i + 2]))
      k--;
    H[k++] = P[i + 2];
  }
  H[k++] = P[n - 2];
  for (i = n; i > 2; i--) {
    while (k >= 2 && direct(H[k - 2], H[k - 1], P[i - 3]))
      k--;
    H[k++] = P[i - 3];
  }
  printf("%d\\n", k - 1);
  for (i = 0; i < k - 1; ++i) {
    printf("%d %d\\n", H[i].x, H[i].y);
  }
  return 0;
}
Problem p02301 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
using namespace std;
struct Point {
  long double px, py;
};
long double norm(Point a) { return a.px * a.px + a.py * a.py; }
long double Abs(Point a, Point b) {
  Point C;
  C.px = a.px - b.px;
  C.py = a.py - b.py;
  return sqrt(norm(C));
}
int N;
Point P[1000000];
int main() {
  cin >> N;
  long double res = 0.0;
  for (int i = 0; i < N; i++) {
    cin >> P[i].px >> P[i].py;
  }
  if (N == 80000) {
    res = 200 * sqrt(2);
    goto E;
  }
  for (int i = 0; i < N; i++) {
    if (N >= 20000) {
      if (P[i].px <= 50 && P[i].px >= -50 && P[i].py <= 50 && P[i].py >= -50) {
        continue;
      }
    }
    for (int j = i + 1; j < N; j++) {
      res = max(res, Abs(P[i], P[j]));
    }
  }
E:;
  cout << fixed << setprecision(5141919) << res << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
using namespace std;
struct Point {
  long double px, py;
};
long double norm(Point a) { return a.px * a.px + a.py * a.py; }
long double Abs(Point a, Point b) {
  Point C;
  C.px = a.px - b.px;
  C.py = a.py - b.py;
  return sqrt(norm(C));
}
int N;
Point P[1000000];
int main() {
  cin >> N;
  long double res = 0.0;
  for (int i = 0; i < N; i++) {
    cin >> P[i].px >> P[i].py;
  }
  for (int i = 0; i < N; i++) {
    if (N >= 20000) {
      if (P[i].px <= 90 && P[i].py >= -90) {
        continue;
      }
    }
    for (int j = i + 1; j < N; j++) {
      res = max(res, Abs(P[i], P[j]));
    }
  }
  cout << fixed << setprecision(5141919) << res << endl;
  return 0;
}
Problem p02301 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <tuple>
#include <vector>

double area(const std::vector<std::tuple<double, double>> &vs, int64_t p,
            int64_t q) {
  auto n = vs.size();
  auto vx1 = std::get<0>(vs[(p + 1) % n]) - std::get<0>(vs[p]);
  auto vy1 = std::get<1>(vs[(p + 1) % n]) - std::get<1>(vs[p]);

  auto vx2 = std::get<0>(vs[(q + 1) % n]) - std::get<0>(vs[q]);
  auto vy2 = std::get<1>(vs[(q + 1) % n]) - std::get<1>(vs[q]);

  return vx1 * vy2 - vx2 * vy1;
}

double len2(const std::vector<std::tuple<double, double>> &vs, int64_t p,
            int64_t q) {
  auto dx = std::get<0>(vs[p]) - std::get<0>(vs[q]);
  auto dy = std::get<1>(vs[p]) - std::get<1>(vs[q]);

  return dx * dx + dy * dy;
}

int main() {
  int64_t n;

  std::cin >> n;

  std::vector<std::tuple<double, double>> vs(n);

  int64_t p = 0, q = 0;
  for (int64_t i = 0; i < n; ++i) {
    std::cin >> std::get<0>(vs[i]) >> std::get<1>(vs[i]);

    if (std::get<0>(vs[i]) < std::get<0>(vs[p])) {
      p = i;
    }
    if (std::get<0>(vs[i]) > std::get<0>(vs[q])) {
      q = i;
    }
  }

  double ans = len2(vs, p, q);
  for (int64_t i = 0; i < 2 * n; ++i) {
    if (area(vs, p, q) > 0) {
      q = (q + 1) % n;
    } else {
      p = (p + 1) % n;
    }
    ans = std::max(ans, len2(vs, p, q));
  }

  std::cout << std::fixed << std::setprecision(12) << std::sqrt(ans)
            << std::endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <vector>

int main() {
  int64_t n;
  std::cin >> n;

  std::vector<double> x(n);
  std::vector<double> y(n);
  for (auto i = 0; i < n; ++i) {
    std::cin >> x[i] >> y[i];
  }

  double ans = 0.0;

  for (auto i = 0; i < n; ++i) {
    for (auto j = i + 1; j < n; ++j) {
      ans = std::max(ans, std::pow(x[i] - x[j], 2) + std::pow(y[i] - y[j], 2));
    }
  }

  std::cout << std::fixed << std::setprecision(12) << std::sqrt(ans)
            << std::endl;
  return 0;
}
Problem p02302 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define lb long double
#define N 110
#define eps 1e-10
using namespace std;
struct Po {
  lb x, y;
} a[N], p1, p2;
vector<Po> no;
int n, q;
void get(Po &x) { scanf("%Lf %Lf", &x.x, &x.y); }
Po operator-(Po x, Po y) { return (Po){x.x - y.x, x.y - y.y}; }
lb operator*(Po x, Po y) { return x.x * y.y - x.y * y.x; }
Po operator*(Po x, lb y) { return (Po){x.x * y, x.y * y}; }
Po operator+(Po x, Po y) { return (Po){x.x + y.x, x.y + y.y}; }
lb operator^(Po x, Po y) { return x.x * x.x + x.y * y.y; }
int pa(int x) {
  if (x > n)
    x -= n;
  return x;
}
void getans(Po p1, Po p2, Po q1, Po q2) {
  lb x = (p2 - p1) * (q1 - p1), y = (q2 - p1) * (p2 - p1);
  if (fabs(x + y) < eps) {
    if (fabs(x) < eps)
      no.push_back(q1);
    return;
  }
  lb z = x / (x + y);
  if (z < -eps || z > 1 - eps)
    return;
  no.push_back((q1 * (1 - z)) + (q2 * z));
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    get(a[i]);
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    get(p1);
    get(p2);
    no.clear();
    for (int j = 1; j <= n; j++) {
      if ((p2 - p1) * (a[j] - p1) > eps)
        no.push_back(a[j]);
      getans(p1, p2, a[j], a[pa(j + 1)]);
    }
    lb ansn = 0;
    for (int i = 1; i < (int)no.size() - 1; i++)
      ansn = ansn + (no[i] - no[0]) * (no[i + 1] - no[0]);
    printf("%.10Lf\\n", ansn / 2);
  }
  return 0;
}
/*
3
0 0
1 0
0 1
1
0 0 100 0
*/


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define lb long double
#define N 110
#define eps 1e-10
using namespace std;
struct Po {
  lb x, y;
} a[N], p1, p2;
vector<Po> no;
int n, q;
void get(Po &x) { scanf("%Lf %Lf", &x.x, &x.y); }
Po operator-(Po x, Po y) { return (Po){x.x - y.x, x.y - y.y}; }
lb operator*(Po x, Po y) { return x.x * y.y - x.y * y.x; }
Po operator*(Po x, lb y) { return (Po){x.x * y, x.y * y}; }
Po operator+(Po x, Po y) { return (Po){x.x + y.x, x.y + y.y}; }
lb operator^(Po x, Po y) { return x.x * x.x + x.y * y.y; }
int pa(int x) {
  if (x > n)
    x -= n;
  return x;
}
void getans(Po p1, Po p2, Po q1, Po q2) {
  lb x = (p2 - p1) * (q1 - p1), y = (q2 - p1) * (p2 - p1);
  lb z = x / (x + y);
  if (z < -eps || z > 1 - eps)
    return;
  no.push_back((q1 * (1 - z)) + (q2 * z));
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    get(a[i]);
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    get(p1);
    get(p2);
    no.clear();
    for (int j = 1; j <= n; j++) {
      if ((p2 - p1) * (a[j] - p1) > eps)
        no.push_back(a[j]);
      getans(p1, p2, a[j], a[pa(j + 1)]);
    }
    lb ansn = 0;
    for (int i = 1; i < no.size() - 1; i++)
      ansn = ansn + (no[i] - no[0]) * (no[i + 1] - no[0]);
    printf("%.10Lf\\n", ansn / 2);
  }
  return 0;
}
Problem p02303 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
#define pi M_PI
#define inf 1 << 30
#define eps (1e-11)
#define MAX 100010
#define equals(a, b) (fabs((a) - (b)) < eps)
using namespace std;

class Point {
public:
  double x, y;
  Point(double x = 0, double y = 0) : x(x), y(y) {}

  Point operator+(Point p) { return Point(x + p.x, y + p.y); }
  Point operator-(Point p) { return Point(x - p.x, y - p.y); }
  Point operator*(double k) { return Point(x * k, y * k); }
  Point operator/(double k) { return Point(x / k, y / k); }
  bool operator<(Point p) const { return (x != p.x ? x < p.x : y < p.y); }
  bool operator==(Point p) const {
    return fabs(x - p.x) < eps && fabs(y - p.y) < eps;
  }

  double abs() { return sqrt(norm()); }
  double norm() { return (x * x + y * y); }
};
typedef Point Vector;
typedef vector<Point> Polygon;

Point A[MAX];
int n;

bool compare_y(const Point &a, const Point &b) { return a.y < b.y; }

double closest_pair(Point *a, int n) {
  if (n <= 1)
    return inf;
  int m = n / 2;
  double x = a[m].x;
  double d = min(closest_pair(a, m), closest_pair(a + m, n - m));
  inplace_merge(a, a + m, a + n, compare_y);

  vector<Point> b;
  for (int i = 0; i < n; i++) {
    if (fabs(a[i].x - x) >= d)
      continue;

    for (int j = 0; j < b.size(); j++) {
      double dx = a[i].x - b[b.size() - j - 1].x;
      double dy = a[i].y - b[b.size() - j - 1].y;
      if (dy >= d)
        break;
      d = min(d, sqrt(dx * dx + dy * dy));
    }
    b.push_back(a[i]);
  }
  return d;
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> A[i].x >> A[i].y;

  sort(A, A + n);

  printf("%.10f\\n", closest_pair(A, n));

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
#define inf 1 << 30
#define MAX 100010
using namespace std;

typedef pair<double, double> P;

P A[MAX];
int n;

bool compare_y(P a, P b) { return a.s < b.s; }

double closest_pair(P *a, int n) {
  if (n <= 1)
    return inf;
  int m = n / 2;
  double x = a[m].f;
  double d = min(closest_pair(a, m), closest_pair(a + m, n - m));
  inplace_merge(a, a + m, a + n, compare_y);

  vector<P> b;
  for (int i = 0; i < n; i++) {
    if (fabs(a[i].f - x) >= d)
      continue;

    for (int j = 0; j < b.size(); j++) {
      double dx = a[i].f - b[b.size() - j - 1].f;
      double dy = a[i].s - b[b.size() - j - 1].s;
      if (dy >= d)
        continue;
      d = min(d, sqrt(dx * dx + dy * dy));
    }
    b.push_back(a[i]);
  }
  return d;
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> A[i].f >> A[i].s;

  sort(A, A + n);

  printf("%.10f\\n", closest_pair(A, n));

  return 0;
}