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

#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define pb emplace_back
typedef long long ll;
typedef pair<int, int> pint;

#define eps (1e-10)
struct Point {
  double x, y;
  Point() {}
  Point(double x, double y) : 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*(Point p) {
    return Point(x * p.x - y * p.y, x * p.y + y * p.x);
  }
  Point operator*(double k) { return Point(x * k, y * k); }
  double norm() { return x * x + y * y; }
  double abs() { return sqrt(norm()); }
  bool operator==(const Point &p) const {
    return fabs(x - p.x) < eps && fabs(y - p.y) < eps;
  }
  double arg() { return atan2(y, x); }
  double dot(Point p) { return x * p.x + y * p.y; }
  double det(Point p) { return x * p.y - y * p.x; }
};
bool cmp_x(const Point &p, const Point &q) {
  if (p.x != q.x)
    return p.x < q.x;
  return p.y < q.y;
}
struct Line {
  Point p1, p2;
  Line() {}
  Line(Point p1, Point p2) : p1(p1), p2(p2) {}
};
struct Circle {
  double r;
  Point p;
  Circle() {}
  Circle(Point p, double r) : p(p), r(r) {}
};
int ccw(Point a, Point b, Point c) {
  Point t1 = b - a, t2 = c - a;
  if (t1.det(t2) > eps)
    return 1; // counter clockwise
  if (t1.det(t2) < -eps)
    return -1; // clockwise
  if (t1.dot(t2) < -eps)
    return 2; // c-a-b online
  if (t1.norm() < t2.norm())
    return -2; // a-b-c online
  return 0;    // a-c-b online
}
Point project(Line l, Point p) {
  Point base = l.p2 - l.p1;
  double r = (p - l.p1).dot(base) / base.norm();
  return l.p1 + base * r;
}
double distance(Line l, Point p) {
  Point r = project(l, p);
  return (p - r).abs();
  /*
  if(abs(ccw(l.p1,l.p2,r))==0) return (p-r).abs();//projection not online
  else return min((p-l.p1).abs(),(p-l.p2).abs());
  */
}
bool isIntersectCC(Circle c1, Circle c2) {
  return (c1.p - c2.p).abs() <= c1.r + c2.r + eps;
}
bool isIntersectCL(Circle c, Line l) { return distance(l, c.p) <= c.r + eps; }
pair<Point, Point> CrossPointsCC(Circle c1, Circle c2) {
  assert(isIntersectCC(c1, c2));
  double d = (c1.p - c2.p).abs();
  double k = acos((d * d + c1.r * c1.r - c2.r * c2.r) / (c1.r * d * 2));
  return make_pair(c1.p + (c2.p - c1.p) * Point(cos(k), sin(k)) * (c1.r / d),
                   c1.p + (c2.p - c1.p) * Point(cos(-k), sin(-k)) * (c1.r / d));
}
pair<Point, Point> CrossPointsCL(Circle c, Line l) {
  assert(isIntersectCL(c, l));
  Point p = project(l, c.p);
  double q = sqrt(c.r * c.r - (p - c.p).norm());
  Point e = (l.p2 - l.p1) * (1.0 / (l.p2 - l.p1).abs());
  return make_pair(p + e * q, p - e * q);
}
int main() {
  double cx, cy, r;
  double x1, y1, x2, y2;
  int q;
  cin >> cx >> cy >> r;
  Circle c(Point(cx, cy), r);
  cin >> q;
  rep(i, q) {
    cin >> x1 >> y1 >> x2 >> y2;
    Line l(Point(x1, y1), Point(x2, y2));
    pair<Point, Point> pp = CrossPointsCL(c, l);
    if (!cmp_x(pp.first, pp.second))
      swap(pp.first, pp.second);
    cout << fixed << setprecision(12) << pp.first.x << " " << pp.first.y << " "
         << pp.second.x << " " << pp.second.y << endl;
  }
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define pb emplace_back
typedef long long ll;
typedef pair<int, int> pint;

#define eps (1e-10)
struct Point {
  double x, y;
  Point() {}
  Point(double x, double y) : 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*(Point p) {
    return Point(x * p.x - y * p.y, x * p.y + y * p.x);
  }
  Point operator*(double k) { return Point(x * k, y * k); }
  double norm() { return x * x + y * y; }
  double abs() { return sqrt(norm()); }
  bool operator==(const Point &p) const {
    return fabs(x - p.x) < eps && fabs(y - p.y) < eps;
  }
  double arg() { return atan2(y, x); }
  double dot(Point p) { return x * p.x + y * p.y; }
  double det(Point p) { return x * p.y - y * p.x; }
};
bool cmp_x(const Point &p, const Point &q) {
  if (p.x != q.x)
    return p.x < q.x;
  return p.y < q.y;
}
struct Line {
  Point p1, p2;
  Line() {}
  Line(Point p1, Point p2) : p1(p1), p2(p2) {}
};
struct Circle {
  double r;
  Point p;
  Circle() {}
  Circle(Point p, double r) : p(p), r(r) {}
};
int ccw(Point a, Point b, Point c) {
  Point t1 = b - a, t2 = c - a;
  if (t1.det(t2) > eps)
    return 1; // counter clockwise
  if (t1.det(t2) < -eps)
    return -1; // clockwise
  if (t1.dot(t2) < -eps)
    return 2; // c-a-b online
  if (t1.norm() < t2.norm())
    return -2; // a-b-c online
  return 0;    // a-c-b online
}
Point project(Line l, Point p) {
  Point base = l.p2 - l.p1;
  double r = (p - l.p1).dot(base) / base.norm();
  return l.p1 + base * r;
}
double distance(Line l, Point p) {
  Point r = project(l, p);
  if (abs(ccw(l.p1, l.p2, r)) == 0)
    return (p - r).abs(); // projection not online
  else
    return min((p - l.p1).abs(), (p - l.p2).abs());
}
bool isIntersectCC(Circle c1, Circle c2) {
  return (c1.p - c2.p).abs() <= c1.r + c2.r + eps;
}
bool isIntersectCL(Circle c, Line l) { return distance(l, c.p) <= c.r + eps; }
pair<Point, Point> CrossPointsCC(Circle c1, Circle c2) {
  assert(isIntersectCC(c1, c2));
  double d = (c1.p - c2.p).abs();
  double k = acos((d * d + c1.r * c1.r - c2.r * c2.r) / (c1.r * d * 2));
  return make_pair(c1.p + (c2.p - c1.p) * Point(cos(k), sin(k)) * (c1.r / d),
                   c1.p + (c2.p - c1.p) * Point(cos(-k), sin(-k)) * (c1.r / d));
}
pair<Point, Point> CrossPointsCL(Circle c, Line l) {
  assert(isIntersectCL(c, l));
  Point p = project(l, c.p);
  double q = sqrt(c.r * c.r - (p - c.p).norm());
  Point e = (l.p2 - l.p1) * (1.0 / (l.p2 - l.p1).abs());
  return make_pair(p + e * q, p - e * q);
}
int main() {
  double cx, cy, r;
  double x1, y1, x2, y2;
  int q;
  cin >> cx >> cy >> r;
  Circle c(Point(cx, cy), r);
  cin >> q;
  rep(i, q) {
    cin >> x1 >> y1 >> x2 >> y2;
    Line l(Point(x1, y1), Point(x2, y2));
    pair<Point, Point> pp = CrossPointsCL(c, l);
    if (!cmp_x(pp.first, pp.second))
      swap(pp.first, pp.second);
    cout << fixed << setprecision(12) << pp.first.x << " " << pp.first.y << " "
         << pp.second.x << " " << pp.second.y << endl;
  }
  return 0;
}