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

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
using namespace std;
typedef long long LL;
typedef complex<double> P;
typedef vector<P> L;
typedef vector<P> Pol;
const double EPS = 1e-5;
int sign(double x) { return x > EPS ? 1 : x < -EPS ? -1 : 0; }

// テ・ツ??ァツゥツ催」ツδサテ・ツ、ツ姪ァツゥツ?
double dot(P a, P b) { return real(conj(a) * b); }
double cross(P a, P b) { return imag(conj(a) * b); }
int ccw(P a, P b, P c) {
  b -= a;
  c -= a;
  return sign(cross(b, c)) ?: dot(b, c) < 0 ? 2 : norm(b) < norm(c) ? -2 : 0;
}

P vec(L l) { return l[1] - l[0]; }
vector<P> pLL(L l, L m) {
  double A = cross(vec(l), vec(m));
  double B = cross(vec(l), l[1] - m[0]);
  if (sign(A) == 0 && sign(B) == 0)
    return {
        l[0], l[1], m[0],
        m[1]}; // テ、ツコツ古ァツ崢エテァツキツ堙」ツ?古ゥツ?催」ツ?ェテ」ツ?」テ」ツ?ヲテ」ツ??」ツつ?
  if (sign(A) == 0)
    return {}; // テァツ崢エテァツキツ堙」ツ?古、ツコツ、テ」ツつ湘」ツつ嘉」ツ?ェテ」ツ??
  return {m[0] + vec(m) * B / A};
}

// テ・ツ?クテ・ツ、ツ堙ィツァツ津・ツスツ「テ」ツ?ョテァツ崢エテァツキツ堙」ツ?ォテ」ツつ暗」ツつ凝・ツ按?ヲツ鳴ュテ」ツ?づァツ崢エテァツキツ堙」ツ?ョテ・ツキツヲテ・ツ?エテ」ツ??」ツ?妥ヲツョツ凝」ツ??
// verify : aoj1283
Pol convex_cut(const Pol &A, L l) {
  int n = A.size();
  Pol B;
  for (int i = 0; i < n; i++) {
    P a = A[i], b = A[(i + 1) % n];
    if (ccw(l[0], l[1], a) != -1)
      B.push_back(
          a); // Aテ」ツ?古ァツ崢エテァツキツ嗟テ」ツ?ョテ・ツ渉ウテ・ツ?エテ」ツ?ァテ」ツ?ェテ」ツ??
    if (ccw(l[0], l[1], a) * ccw(l[0], l[1], b) < 0)
      B.push_back(pLL(l, {a, b})[0]);
  }
  return B;
}
// テ・ツ楪づァツ崢エテ、ツコツ古ァツュツ嘉・ツ按?ァツキツ?
// verify: maximamcup2013 D
L bisector(P a, P b) {
  P mid = (a + b) / 2.0;
  P vec = (mid - a) * P(0.0, 1.0);
  return {mid, mid + vec};
}
// テァツつケテゥツ崢?・ツ青?sテ」ツ?ョテ」ツ??」ツ?。sテァツ閉ェテァツ崢ョテ」ツ?ョテ」ツδ愿」ツδュテ」ツδ偲」ツつ、テゥツ?佚・ツ淞?
// verify: maximamcup2013 D
Pol voronoi_cell(Pol A, const vector<P> &ps, int s) {
  for (int i = 0; i < ps.size(); i++) {
    if (i != s)
      A = convex_cut(A, bisector(ps[s], ps[i]));
  }
  return A;
}

double area(const Pol &A) {
  double res = 0;
  int n = A.size();
  for (int i = 0; i < n; i++) {
    res += cross(A[i], A[(i + 1) % n]);
  }
  return abs(res) / 2.0;
}
Pol unite(Pol P, Pol b) {
  for (int i = 0; i < b.size(); i++) {
    L l = {b[i], b[(i + 1) % b.size()]};
    P = convex_cut(P, l);
  }
  return P;
}

int main() {
  int N, M;
  while (cin >> N >> M && N > 0) {
    vector<P> vp(N);
    REP(i, N) {
      double x, y;
      cin >> x >> y;
      vp[i] = {x, y};
    }
    vector<Pol> pols(N);
    Pol uni;
    uni.push_back(P(-1e6, -1e6));
    uni.push_back(P(+1e6, -1e6));
    uni.push_back(P(+1e6, +1e6));
    uni.push_back(P(-1e6, +1e6));
    REP(i, N) pols[i] = voronoi_cell(uni, vp, i);

    vector<double> exp(N);

    REP(_, M) {
      Pol bal;
      double bx, by, dx, dy, score;
      cin >> bx >> by >> dx >> dy >> score;
      bal.push_back(P(bx - dx, by - dy));
      bal.push_back(P(bx + dx, by - dy));
      bal.push_back(P(bx + dx, by + dy));
      bal.push_back(P(bx - dx, by + dy));
      double SUM = dx * dy * 4;
      double verify = 0;
      REP(i, N) {
        double ratio = area(unite(pols[i], bal)) / SUM;
        exp[i] += score * ratio;
        verify += ratio;
      }
      assert(sign(verify - 1) == 0);
    }
    printf("%.6f\\n", *max_element(exp.begin(), exp.end()));
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
using namespace std;
typedef long long LL;
typedef complex<double> P;
typedef vector<P> L;
typedef vector<P> Pol;
const double EPS = 1e-8;
int sign(double x) { return x > EPS ? 1 : x < -EPS ? -1 : 0; }

// テ・ツ??ァツゥツ催」ツδサテ・ツ、ツ姪ァツゥツ?
double dot(P a, P b) { return real(conj(a) * b); }
double cross(P a, P b) { return imag(conj(a) * b); }
int ccw(P a, P b, P c) {
  b -= a;
  c -= a;
  return sign(cross(b, c)) ?: dot(b, c) < 0 ? 2 : norm(b) < norm(c) ? -2 : 0;
}

P vec(L l) { return l[1] - l[0]; }
vector<P> pLL(L l, L m) {
  double A = cross(vec(l), vec(m));
  double B = cross(vec(l), l[1] - m[0]);
  if (sign(A) == 0 && sign(B) == 0)
    return {
        l[0], l[1], m[0],
        m[1]}; // テ、ツコツ古ァツ崢エテァツキツ堙」ツ?古ゥツ?催」ツ?ェテ」ツ?」テ」ツ?ヲテ」ツ??」ツつ?
  if (sign(A) == 0)
    return {}; // テァツ崢エテァツキツ堙」ツ?古、ツコツ、テ」ツつ湘」ツつ嘉」ツ?ェテ」ツ??
  return {m[0] + vec(m) * B / A};
}

// テ・ツ?クテ・ツ、ツ堙ィツァツ津・ツスツ「テ」ツ?ョテァツ崢エテァツキツ堙」ツ?ォテ」ツつ暗」ツつ凝・ツ按?ヲツ鳴ュテ」ツ?づァツ崢エテァツキツ堙」ツ?ョテ・ツキツヲテ・ツ?エテ」ツ??」ツ?妥ヲツョツ凝」ツ??
// verify : aoj1283
Pol convex_cut(const Pol &A, L l) {
  int n = A.size();
  Pol B;
  for (int i = 0; i < n; i++) {
    P a = A[i], b = A[(i + 1) % n];
    if (ccw(l[0], l[1], a) != -1)
      B.push_back(
          a); // Aテ」ツ?古ァツ崢エテァツキツ嗟テ」ツ?ョテ・ツ渉ウテ・ツ?エテ」ツ?ァテ」ツ?ェテ」ツ??
    if (ccw(l[0], l[1], a) * ccw(l[0], l[1], b) < 0)
      B.push_back(pLL(l, {a, b})[0]);
  }
  return B;
}
// テ・ツ楪づァツ崢エテ、ツコツ古ァツュツ嘉・ツ按?ァツキツ?
// verify: maximamcup2013 D
L bisector(P a, P b) {
  P mid = (a + b) / 2.0;
  P vec = (mid - a) * P(0.0, 1.0);
  return {mid, mid + vec};
}
// テァツつケテゥツ崢?・ツ青?sテ」ツ?ョテ」ツ??」ツ?。sテァツ閉ェテァツ崢ョテ」ツ?ョテ」ツδ愿」ツδュテ」ツδ偲」ツつ、テゥツ?佚・ツ淞?
// verify: maximamcup2013 D
Pol voronoi_cell(Pol A, const vector<P> &ps, int s) {
  for (int i = 0; i < ps.size(); i++) {
    if (i != s)
      A = convex_cut(A, bisector(ps[s], ps[i]));
  }
  return A;
}

double area(const Pol &A) {
  double res = 0;
  int n = A.size();
  for (int i = 0; i < n; i++) {
    res += cross(A[i], A[(i + 1) % n]);
  }
  return abs(res) / 2.0;
}
Pol unite(Pol P, Pol b) {
  for (int i = 0; i < b.size(); i++) {
    L l = {b[i], b[(i + 1) % b.size()]};
    P = convex_cut(P, l);
  }
  return P;
}

int main() {
  int N, M;
  while (cin >> N >> M && N > 0) {
    vector<P> vp(N);
    REP(i, N) {
      double x, y;
      cin >> x >> y;
      vp[i] = {x, y};
    }
    vector<Pol> pols(N);
    Pol uni;
    uni.push_back(P(-1e4, -1e4));
    uni.push_back(P(+1e4, -1e4));
    uni.push_back(P(+1e4, +1e4));
    uni.push_back(P(-1e4, +1e4));
    REP(i, N) pols[i] = voronoi_cell(uni, vp, i);

    vector<double> exp(N);

    REP(_, M) {
      Pol bal;
      double bx, by, dx, dy, score;
      cin >> bx >> by >> dx >> dy >> score;
      bal.push_back(P(bx - dx, by - dy));
      bal.push_back(P(bx + dx, by - dy));
      bal.push_back(P(bx + dx, by + dy));
      bal.push_back(P(bx - dx, by + dy));
      double SUM = dx * dy * 4;
      double verify = 0;
      REP(i, N) {
        double ratio = area(unite(pols[i], bal)) / SUM;
        exp[i] += score * ratio;
        verify += ratio;
      }
      assert(sign(verify - 1) == 0);
    }
    printf("%.6f\\n", *max_element(exp.begin(), exp.end()));
  }
  return 0;
}