Problem p00249 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef complex<double> point;
typedef pair<point, point> line;
const double EPS = 1e-8;

// テ・ツ??ァツゥツ?
double dot(point a, point b) { return real(conj(a) * b); }

// テ・ツ、ツ姪ァツゥツ?
double cross(point a, point b) { return imag(conj(a) * b); }

int ccw(point a, point b, point c) {
  point d = b - a;
  point e = c - a;
  if (cross(d, e) > 0)
    return 1; // テ・ツキツヲテ・ツ?エ
  if (cross(d, e) < 0)
    return -1; // テ・ツ渉ウテ・ツ?エ
  if (dot(d, e) < 0)
    return 2; // onlineback
  if (abs(d) < abs(e))
    return -2; // onlinefront
  return 0;    // onsegment
}

point crosspoint_ll(line l1, line l2) {
  double a = cross(l1.second - l1.first, l2.second - l2.first);
  double b = cross(l1.second - l1.first, l1.second - l2.first);
  if (fabs(a) < EPS && fabs(b) < EPS)
    return l2.first;
  else if (fabs(a) >= EPS)
    return l2.first + b / a * (l2.second - l2.first);
}

vector<point> Convex_Cut(vector<point> polygon, line l) {
  vector<point> res;
  for (int i = 0; i < polygon.size(); i++) {
    point a = polygon[i], b = polygon[(i + 1) % polygon.size()];
    if (ccw(l.first, l.second, a) != -1)
      res.push_back(a);
    if (ccw(l.first, l.second, a) * ccw(l.first, l.second, b) < 0)
      res.push_back(crosspoint_ll(line(a, b), l));
  }
  return res;
}

double get_area(vector<point> polygon) {
  double res = 0;
  for (int i = 0; i < polygon.size(); i++)
    res += cross(polygon[i], polygon[(i + 1) % polygon.size()]);
  return res / 2;
}

int n, d, V, x, y;

double bynary_search(vector<point> polygon, point a, point b) {
  b -= a;
  for (int i = 0; i < n; i++)
    polygon[i] -= a, polygon[i] = polygon[i] * conj(b) / abs(b);
  double l = 0, r = (1e9), m;
  while (l + EPS < r) {
    m = (l + r) / 2;
    point A = point(abs(b), m), B = point(0, m);
    if (get_area(Convex_Cut(polygon, line(A, B))) * d < V)
      l = m + EPS;
    else
      r = m;
  }
  return l;
}

int main() {
  vector<point> polygon;
  while (1) {
    double ans = 0;
    cin >> n >> d >> V;
    if (!n && !d && !V)
      break;
    for (int i = 0; i < n; i++)
      cin >> x >> y, polygon.push_back(point(x, y));
    for (int i = 0; i < n; i++) {
      point a = polygon[i], b = polygon[(i + 1) % n];
      ans = max(ans, bynary_search(polygon, a, b));
    }
    printf("%.9f\\n", ans);
    polygon.clear();
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef complex<double> point;
typedef pair<point, point> line;
const double EPS = 1e-8;

// テ・ツ??ァツゥツ?
double dot(point a, point b) { return real(conj(a) * b); }

// テ・ツ、ツ姪ァツゥツ?
double cross(point a, point b) { return imag(conj(a) * b); }

int ccw(point a, point b, point c) {
  point d = b - a;
  point e = c - a;
  if (cross(d, e) > 0)
    return 1; // テ・ツキツヲテ・ツ?エ
  if (cross(d, e) < 0)
    return -1; // テ・ツ渉ウテ・ツ?エ
  if (dot(d, e) < 0)
    return 2; // onlineback
  if (abs(d) < abs(e))
    return -2; // onlinefront
  return 0;    // onsegment
}

point crosspoint_ll(line l1, line l2) {
  double a = cross(l1.second - l1.first, l2.second - l2.first);
  double b = cross(l1.second - l1.first, l1.second - l2.first);
  if (fabs(a) < EPS && fabs(b) < EPS)
    return l2.first;
  else if (fabs(a) >= EPS)
    return l2.first + b / a * (l2.second - l2.first);
}

vector<point> Convex_Cut(vector<point> polygon, line l) {
  vector<point> res;
  for (int i = 0; i < polygon.size(); i++) {
    point a = polygon[i], b = polygon[(i + 1) % polygon.size()];
    if (ccw(l.first, l.second, a) != -1)
      res.push_back(a);
    if (ccw(l.first, l.second, a) * ccw(l.first, l.second, b) < 0)
      res.push_back(crosspoint_ll(line(a, b), l));
  }
  return res;
}

double get_area(vector<point> polygon) {
  double res = 0;
  for (int i = 0; i < polygon.size(); i++)
    res += cross(polygon[i], polygon[(i + 1) % polygon.size()]);
  return res / 2;
}

int n, d, V, x, y;

double bynary_search(vector<point> polygon, point a, point b) {
  b -= a;
  for (int i = 0; i < n; i++)
    polygon[i] -= a, polygon[i] = polygon[i] * conj(b) / abs(b);
  double l = 0, r = (1e9), m;
  while (l < r) {
    m = (l + r) / 2;
    point A = point(abs(b), m), B = point(0, m);
    if (get_area(Convex_Cut(polygon, line(A, B))) * d < V)
      l = m + EPS;
    else
      r = m;
  }
  return l;
}

int main() {
  vector<point> polygon;
  double ans = 0;
  while (1) {
    cin >> n >> d >> V;
    if (!n && !d && !V)
      break;
    for (int i = 0; i < n; i++)
      cin >> x >> y, polygon.push_back(point(x, y));
    for (int i = 0; i < n; i++) {
      point a = polygon[i], b = polygon[(i + 1) % n];
      ans = max(ans, bynary_search(polygon, a, b));
    }
    printf("%.9f\\n", ans);
    polygon.clear();
  }
  return 0;
}