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

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define rep(i, a, n) for (int(i) = (a); (i) < (n); (i)++)
#define repq(i, a, n) for (int(i) = (a); (i) <= (n); (i)++)
#define repr(i, a, n) for (int(i) = (a); (i) >= (n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a, b) (abs((a) - (b)) < EPS)
#define EQV(a, b) (EQ((a).X, (b).X) && EQ((a).Y, (b).Y))
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int const MOD = 1000000007;
ll mod_pow(ll x, ll n) {
  return (!n) ? 1 : (mod_pow((x * x) % MOD, n / 2) * ((n & 1) ? x : 1)) % MOD;
}
int madd(int a, int b) { return (a + b) % MOD; }
int msub(int a, int b) { return (a - b + MOD) % MOD; }
int mmul(int a, int b) { return (a * b) % MOD; }
int minv(int a) { return mod_pow(a, MOD - 2); }
int mdiv(int a, int b) { return mmul(a, minv(b)); }

namespace std {
bool operator<(const P &a, const P &b) {
  return a.X != b.X ? a.X < b.X : a.Y < b.Y;
}
} // namespace std

// 2???????????????????????????????±???????
double dot(P a, P b) { return (a.X * b.X + a.Y * b.Y); }

// 2???????????????????????????????±???????
double cross(P a, P b) { return (a.X * b.Y - a.Y * b.X); }

// ??´??? a1, a2 ??¨??´???b1, b2?????????????±???????
// Verified: AOJ CGL_2_C.cpp
P crossp_ll(P a1, P a2, P b1, P b2) {
  double d1 = cross(b2 - b1, b1 - a1);
  double d2 = cross(b2 - b1, a2 - a1);
  if (EQ(d1, 0) && EQ(d2, 0))
    return a1; // same line
  if (EQ(d2, 0))
    assert(false); // precondition not satisfied
  return a1 + d1 / d2 * (a2 - a1);
}

// ????§???¢????¬????????????¢???
double area_n(const vector<P> &v) {
  double ans = 0;
  double x, y, z;
  P init = v[0];
  rep(i, 2, v.size()) {
    x = sqrt(norm(v[i] - init));
    y = sqrt(norm(v[i - 1] - init));
    z = sqrt(norm(v[i] - v[i - 1]));

    double s = (x + y + z) / 2;
    ans += sqrt(s * (s - x) * (s - y) * (s - z));
  }
  return ans;
}

int ccw(P a, P b, P c) {
  b -= a;
  c -= a;
  if (cross(b, c) > EPS)
    return +1;
  if (cross(b, c) < -EPS)
    return -1;
  if (dot(b, c) < 0)
    return +2;
  if (norm(b) < norm(c))
    return -2;
  return 0;
}

// ?????? a1, a2 ??¨?????? b1, b2 ???????????????
// Verified: CGL_2_B: Intersection
bool isec_ss(P a1, P a2, P b1, P b2) {
  return (ccw(a1, a2, b1) * ccw(a1, a2, b2) <= 0) &&
         (ccw(b1, b2, a1) * ccw(b1, b2, a2) <= 0);
}

signed main() {
  double x1, y1, x2, y2;
  while (cin >> x1 >> y1 >> x2 >> y2) {
    if (x1 == y1 && y1 == x2 && x2 == y2 && y2 == 0.0)
      break;
    vector<L> ls;
    vector<P> ps;
    ls.push_back(make_pair(P(x1, y1), P(x2, y2)));
    rep(i, 0, 2) {
      cin >> x1 >> y1 >> x2 >> y2;
      ls.push_back(make_pair(P(x1, y1), P(x2, y2)));
    }

    bool ng = false;
    rep(i, 0, 3) {
      P a1 = ls[i].fr, a2 = ls[i].sc;
      P b1 = ls[(i + 1) % 3].fr, b2 = ls[(i + 1) % 3].sc;
      if (!isec_ss(a1, a2, b1, b2)) {
        ng = true;
        break;
      }
      P temp = crossp_ll(a1, a2, b1, b2);
      // printf("crosspoint: (%.12lf, %.12lf)\\n", temp.X, temp.Y);
      rep(k, 0, ps.size()) {
        if (temp == ps[k]) {
          ng = true;
          break;
        }
      }
      ps.push_back(temp);
    }

    if (ng)
      cout << "kyo" << endl;
    else {
      double ans = fabs(cross(ps[0] - ps[1], ps[0] - ps[2]) / 2.0);
      if (ans < 100000.0 + EPS)
        cout << "syo-kichi" << endl;
      else if (ans < 1000000.0 + EPS)
        cout << "kichi" << endl;
      else if (ans < 1900000.0 + EPS)
        cout << "chu-kichi" << endl;
      else
        cout << "dai-kichi" << endl;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define rep(i, a, n) for (int(i) = (a); (i) < (n); (i)++)
#define repq(i, a, n) for (int(i) = (a); (i) <= (n); (i)++)
#define repr(i, a, n) for (int(i) = (a); (i) >= (n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a, b) (abs((a) - (b)) < EPS)
#define EQV(a, b) (EQ((a).X, (b).X) && EQ((a).Y, (b).Y))
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int const MOD = 1000000007;
ll mod_pow(ll x, ll n) {
  return (!n) ? 1 : (mod_pow((x * x) % MOD, n / 2) * ((n & 1) ? x : 1)) % MOD;
}
int madd(int a, int b) { return (a + b) % MOD; }
int msub(int a, int b) { return (a - b + MOD) % MOD; }
int mmul(int a, int b) { return (a * b) % MOD; }
int minv(int a) { return mod_pow(a, MOD - 2); }
int mdiv(int a, int b) { return mmul(a, minv(b)); }

namespace std {
bool operator<(const P &a, const P &b) {
  return a.X != b.X ? a.X < b.X : a.Y < b.Y;
}
} // namespace std

// 2???????????????????????????????±???????
double dot(P a, P b) { return (a.X * b.X + a.Y * b.Y); }

// 2???????????????????????????????±???????
double cross(P a, P b) { return (a.X * b.Y - a.Y * b.X); }

// ??´??? a1, a2 ??¨??´???b1, b2?????????????±???????
// Verified: AOJ CGL_2_C.cpp
P crossp_ll(P a1, P a2, P b1, P b2) {
  double d1 = cross(b2 - b1, b1 - a1);
  double d2 = cross(b2 - b1, a2 - a1);
  if (EQ(d1, 0) && EQ(d2, 0))
    return a1; // same line
  if (EQ(d2, 0))
    assert(false); // precondition not satisfied
  return a1 + d1 / d2 * (a2 - a1);
}

// ????§???¢????¬????????????¢???
double area_n(const vector<P> &v) {
  double ans = 0;
  double x, y, z;
  P init = v[0];
  rep(i, 2, v.size()) {
    x = sqrt(norm(v[i] - init));
    y = sqrt(norm(v[i - 1] - init));
    z = sqrt(norm(v[i] - v[i - 1]));

    double s = (x + y + z) / 2;
    ans += sqrt(s * (s - x) * (s - y) * (s - z));
  }
  return ans;
}

int ccw(P a, P b, P c) {
  b -= a;
  c -= a;
  if (cross(b, c) > EPS)
    return +1;
  if (cross(b, c) < -EPS)
    return -1;
  if (dot(b, c) < 0)
    return +2;
  if (norm(b) < norm(c))
    return -2;
  return 0;
}

// ?????? a1, a2 ??¨?????? b1, b2 ???????????????
// Verified: CGL_2_B: Intersection
bool isec_ss(P a1, P a2, P b1, P b2) {
  return (ccw(a1, a2, b1) * ccw(a1, a2, b2) <= 0) &&
         (ccw(b1, b2, a1) * ccw(b1, b2, a2) <= 0);
}

signed main() {
  double x1, y1, x2, y2;
  while (cin >> x1 >> y1 >> x2 >> y2) {
    if (x1 == y1 && y1 == x2 && x2 == y2 && y2 == 0.0)
      break;
    vector<L> ls;
    vector<P> ps;
    ls.push_back(make_pair(P(x1, y1), P(x2, y2)));
    rep(i, 0, 2) {
      cin >> x1 >> y1 >> x2 >> y2;
      ls.push_back(make_pair(P(x1, y1), P(x2, y2)));
    }

    bool ng = false;
    rep(i, 0, 3) {
      P a1 = ls[i].fr, a2 = ls[i].sc;
      P b1 = ls[(i + 1) % 3].fr, b2 = ls[(i + 1) % 3].sc;
      if (!isec_ss(a1, a2, b1, b2)) {
        ng = true;
        break;
      }
      P temp = crossp_ll(a1, a2, b1, b2);
      // printf("crosspoint: (%.12lf, %.12lf)\\n", temp.X, temp.Y);
      rep(k, 0, ps.size()) {
        if (temp == ps[k]) {
          ng = true;
          break;
        }
      }
      ps.push_back(temp);
    }

    double ans = area_n(ps);
    if (ng)
      cout << "kyo" << endl;
    else if (ans < 100000.0 + EPS)
      cout << "syo-kichi" << endl;
    else if (ans < 1000000.0 + EPS)
      cout << "kichi" << endl;
    else if (ans < 1900000.0 + EPS)
      cout << "chu-kichi" << endl;
    else
      cout << "dai-kichi" << endl;
    // printf("debug: ans = %.12lf\\n", ans);
  }
  return 0;
}