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

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL << 30)
#define LLINF (1LL << 60)
#define PI 3.14159265359
#define EPS 1e-12
#define int ll

struct vector2D {
  double x;
  double y;
};

vector2D subVector(const vector2D &t1, const vector2D &t2) {
  vector2D ret;
  ret.x = t1.x - t2.x;
  ret.y = t1.y - t2.y;
  return ret;
}

bool hittest(vector2D a, vector2D b, vector2D c, vector2D p) {
  vector2D AB = subVector(b, a);
  vector2D BP = subVector(p, b);

  vector2D BC = subVector(c, b);
  vector2D CP = subVector(p, c);

  vector2D CA = subVector(a, c);
  vector2D AP = subVector(p, a);

  double c1 = AB.x * BP.y - AB.y * BP.x;
  double c2 = BC.x * CP.y - BC.y * CP.x;
  double c3 = CA.x * AP.y - CA.y * AP.x;

  if ((c1 > 0 && c2 > 0 && c3 > 0) || (c1 < 0 && c2 < 0 && c3 < 0)) {
    return true;
  }

  return false;
}

signed main(void) {
  vector2D p1, p2, p3, p4;
  while (~scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &p1.x, &p1.y, &p2.x, &p2.y,
                &p3.x, &p3.y, &p4.x, &p4.y)) {
    if (hittest(p1, p2, p3, p4) || hittest(p1, p2, p4, p3) ||
        hittest(p1, p3, p4, p2) || hittest(p2, p3, p4, p1))
      cout << "NO" << endl;
    else
      cout << "YES" << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL << 30)
#define LLINF (1LL << 60)
#define PI 3.14159265359
#define EPS 1e-12
#define int ll

struct vector2D {
  double x;
  double y;
};

vector2D subVector(const vector2D &t1, const vector2D &t2) {
  vector2D ret;
  ret.x = t1.x - t2.x;
  ret.y = t1.y - t2.y;
  return ret;
}

bool hittest(vector2D a, vector2D b, vector2D c, vector2D p) {
  vector2D AB = subVector(b, a);
  vector2D BP = subVector(p, b);

  vector2D BC = subVector(c, b);
  vector2D CP = subVector(p, c);

  vector2D CA = subVector(a, c);
  vector2D AP = subVector(p, a);

  double c1 = AB.x * BP.y - AB.y * BP.x;
  double c2 = BC.x * CP.y - BC.y * CP.x;
  double c3 = CA.x * AP.y - CA.y * AP.x;

  if ((c1 > 0 && c2 > 0 && c3 > 0) || (c1 < 0 && c2 < 0 && c3 < 0)) {
    return true;
  }

  return false;
}

signed main(void) {
  vector2D p1, p2, p3, p4;
  while (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &p1.x, &p1.y, &p2.x, &p2.y,
               &p3.x, &p3.y, &p4.x, &p4.y)) {
    if (hittest(p1, p2, p3, p4) || hittest(p1, p2, p4, p3) ||
        hittest(p1, p3, p4, p2) || hittest(p2, p3, p4, p1))
      cout << "NO" << endl;
    else
      cout << "YES" << endl;
  }
  return 0;
}