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

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, c)                                                              \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
const double EPS = 1e-8;
const double INF = 1e12;
typedef complex<double> P;
namespace std {
bool operator<(const P &a, const P &b) {
  return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
}
} // namespace std
double cross(const P &a, const P &b) { return imag(conj(a) * b); }
double dot(const P &a, const P &b) { return real(conj(a) * b); }

struct L : public vector<P> {
  L() {}
  L(const P &a, const P &b) {
    push_back(a);
    push_back(b);
  }
};
int ccw(P a, P b, P c) {
  b -= a;
  c -= a;
  if (cross(b, c) > 0)
    return +1; // counter clockwise
  if (cross(b, c) < 0)
    return -1; // clockwise
  if (dot(b, c) < 0)
    return +2; // c--a--b on line
  if (norm(b) < norm(c))
    return -2; // a--b--c on line
  return 0;
}
bool intersectSS(const L &s, const L &t) {
  return ccw(s[0], s[1], t[0]) * ccw(s[0], s[1], t[1]) <= 0 &&
         ccw(t[0], t[1], s[0]) * ccw(t[0], t[1], s[1]) <= 0;
}
bool sameline(const L &l, const L &m) {
  double A = cross(l[1] - l[0], m[1] - m[0]);
  double B = cross(l[1] - l[0], l[1] - m[0]);
  return (abs(A) < EPS && abs(B) < EPS); // same line
}
P crosspoint(const L &l, const L &m) {
  double A = cross(l[1] - l[0], m[1] - m[0]);
  double B = cross(l[1] - l[0], l[1] - m[0]);
  if (abs(A) < EPS && abs(B) < EPS)
    return m[0]; // same line
  return m[0] + B / A * (m[1] - m[0]);
}

int main() {
  while (1) {
    L ls[3];
    bool fff = 0;
    REP(i, 3) {
      int x1, y1, x2, y2;
      cin >> x1 >> y1 >> x2 >> y2;
      if (!x1 && !y1 && !x2 && !y2) {
        fff = 1;
        break;
      }
      ls[i] = L(P(x1, y1), P(x2, y2));
    }
    if (fff)
      break;

    if (!intersectSS(ls[0], ls[1]) || !intersectSS(ls[1], ls[2]) ||
        !intersectSS(ls[2], ls[0]) || sameline(ls[0], ls[1]) ||
        sameline(ls[1], ls[2]) || sameline(ls[2], ls[0])) {
      cout << "kyo" << endl;
      continue;
    }
    P cp[3];
    REP(i, 3) {
      cp[i] = crosspoint(ls[i], ls[(i + 1) % 3]);
      //      cout << cp[i] << endl;
    }
    double S = abs(cross(cp[2] - cp[0], cp[1] - cp[0])) / 2;

    //    cout << S << endl;
    if (S >= 1900000)
      cout << "dai-kichi" << endl;
    else if (S >= 1000000)
      cout << "chu-kichi" << endl;
    else if (S >= 100000)
      cout << "kichi" << endl;
    else if (S > EPS)
      cout << "syo-kichi" << endl;
    else
      cout << "kyo" << endl;
  }
}

Error: -11

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, c)                                                              \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
const double EPS = 1e-8;
const double INF = 1e12;
typedef complex<double> P;
namespace std {
bool operator<(const P &a, const P &b) {
  return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
}
} // namespace std
double cross(const P &a, const P &b) { return imag(conj(a) * b); }
double dot(const P &a, const P &b) { return real(conj(a) * b); }

struct L : public vector<P> {
  L() {}
  L(const P &a, const P &b) {
    push_back(a);
    push_back(b);
  }
};
int ccw(P a, P b, P c) {
  b -= a;
  c -= a;
  if (cross(b, c) > 0)
    return +1; // counter clockwise
  if (cross(b, c) < 0)
    return -1; // clockwise
  if (dot(b, c) < 0)
    return +2; // c--a--b on line
  if (norm(b) < norm(c))
    return -2; // a--b--c on line
  return 0;
}
bool intersectSS(const L &s, const L &t) {
  return ccw(s[0], s[1], t[0]) * ccw(s[0], s[1], t[1]) <= 0 &&
         ccw(t[0], t[1], s[0]) * ccw(t[0], t[1], s[1]) <= 0;
}
bool sameline(const L &l, const L &m) {
  double A = cross(l[1] - l[0], m[1] - m[0]);
  double B = cross(l[1] - l[0], l[1] - m[0]);
  return (abs(A) < EPS && abs(B) < EPS); // same line
}
P crosspoint(const L &l, const L &m) {
  double A = cross(l[1] - l[0], m[1] - m[0]);
  double B = cross(l[1] - l[0], l[1] - m[0]);
  if (abs(A) < EPS && abs(B) < EPS)
    return m[0]; // same line
  return m[0] + B / A * (m[1] - m[0]);
}

int main() {
  while (1) {
    L ls[3];
    REP(i, 3) {
      int x1, y1, x2, y2;
      cin >> x1 >> y1 >> x2 >> y2;
      if (!x1 && !y1 && !x2 && !y2)
        return 0;
      ls[i] = L(P(x1, y1), P(x2, y2));
    }
    if (!intersectSS(ls[0], ls[1]) || !intersectSS(ls[1], ls[2]) ||
        !intersectSS(ls[2], ls[0]) || sameline(ls[0], ls[1]) ||
        sameline(ls[1], ls[2]) || sameline(ls[2], ls[3])) {
      cout << "kyo" << endl;
      continue;
    }
    P cp[3];
    REP(i, 3)
    cp[i] = crosspoint(ls[i], ls[(i + 1) % 3]);
    double S = cross(cp[2] - cp[0], cp[1] - cp[0]) / 2;
    if (S >= 1900000)
      cout << "dai-kichi" << endl;
    else if (S >= 1000000)
      cout << "chu-kichi" << endl;
    else if (S >= 100000)
      cout << "kichi" << endl;
    else if (S > EPS)
      cout << "syo-kichi" << endl;
    else
      cout << "kyo" << endl;
  }
}