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

#include <algorithm>
#include <cmath>
#include <iostream>
#include <set>
#include <utility>
#include <vector>

#include <type_traits>

#define EPS 1e-10
#define R 1

typedef std::pair<double, double> Vec;

Vec operator+(const Vec &lhs, const Vec &rhs) {
  return std::make_pair(lhs.first + rhs.first, lhs.second + rhs.second);
}

Vec operator-(const Vec &lhs, const Vec &rhs) {
  return std::make_pair(lhs.first - rhs.first, lhs.second - rhs.second);
}

Vec operator*(const double &lhs, const Vec &rhs) {
  return std::make_pair(lhs * rhs.first, lhs * rhs.second);
}

double dist(const Vec &lhs, const Vec &rhs) {
  return std::sqrt(std::pow(lhs.first - rhs.first, 2) +
                   std::pow(lhs.second - rhs.second, 2));
}

bool inCircle(const Vec &pt) {
  return (std::pow(pt.first, 2) + std::pow(pt.second, 2) <=
          std::pow(R, 2) + EPS);
}

bool inCircle(const Vec &circ, const Vec &pt) { return inCircle(pt - circ); }

std::pair<Vec, Vec> getCross(const Vec &lhs, const Vec &rhs) {
  double d = dist(lhs, rhs);
  double alpha = std::acos(d / (2 * R));
  double theta = std::atan2(lhs.second - rhs.second, lhs.first - rhs.first);

  return (std::make_pair(rhs + R * std::make_pair(std::cos(theta + alpha),
                                                  std::sin(theta + alpha)),
                         rhs + R * std::make_pair(std::cos(theta - alpha),
                                                  std::sin(theta - alpha))));
}

bool inSquare(const Vec &pt) {
  return ((0 <= pt.first && pt.first <= 10) &&
          (0 <= pt.second && pt.second <= 10));
}

int main(void) {
  using namespace std;

  unsigned int N;
  cin >> N;
  for (; N != 0; cin >> N) {
    vector<pair<double, double>> v;
    v.reserve(N);
    for (int i = 1; i <= N; i++) {
      char sep;
      double x, y;
      cin >> x >> sep >> y;

      v.push_back(make_pair(x, y));
    }

    if (N == 1) {
      cout << 1 << endl;
      continue;
    }

    vector<bool> permTable(N);
    fill(permTable.begin() + 2, permTable.end(), true);
    unsigned int count = 1;
    do {
      vector<unsigned int> tmp;
      tmp.reserve(2);
      for (unsigned int i = 0; i < N; ++i) {
        if (!permTable[i]) {
          tmp.push_back(i);
        }
      }

      if (dist(v[tmp[0]], v[tmp[1]]) <= 2 * R + EPS) {
        auto cross = getCross(v[tmp[0]], v[tmp[1]]);
        unsigned int first = 2;
        unsigned int second = 2;
        for (auto itr = v.begin(); itr != v.end(); itr++) {
          if (*itr == v[tmp[0]] || *itr == v[tmp[1]]) {
            continue;
          } else if (inCircle(*itr, cross.first)) {
            first++;
          } else if (inCircle(*itr, cross.second)) {
            second++;
          }
        }
        if (!inSquare(cross.first)) {
          first = 0;
        }
        if (!inSquare(cross.second)) {
          second = 0;
        }
        count = std::max(count, std::max(first, second));
      }
    } while (std::next_permutation(permTable.begin(), permTable.end()));
    cout << count << endl;
  }
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <set>
#include <utility>
#include <vector>

double dist(std::pair<double, double> lhs, std::pair<double, double> rhs) {
  return std::sqrt(std::pow(lhs.first - rhs.first, 2) +
                   std::pow(lhs.second - rhs.second, 2));
}

int main(void) {
  using namespace std;

  unsigned int N;
  cin >> N;
  for (; N != 0; cin >> N) {
    vector<pair<double, double>> v;
    vector<unsigned int> count(N, 0);
    v.reserve(N);
    for (int i = 1; i <= N; i++) {
      char sep;
      double x, y;
      cin >> x >> sep >> y;

      v.push_back(make_pair(x, y));
    }

    vector<bool> permTable(N);
    fill(permTable.begin() + 2, permTable.end(), true);
    vector<pair<set<unsigned int>, bool>> relation;
    do {
      vector<unsigned int> tmp;
      tmp.reserve(2);
      for (unsigned int i = 0; i < N; ++i) {
        if (!permTable[i]) {
          tmp.push_back(i);
        }
      }

      bool flag;
      if (dist(v[tmp[0]], v[tmp[1]]) < 2.0) {
        flag = true;
      } else {
        flag = false;
      }
      relation.push_back(
          make_pair(set<unsigned int>(tmp.begin(), tmp.end()), flag));
    } while (std::next_permutation(permTable.begin(), permTable.end()));

    for (int i = 0; i < N; i++) {
      for (auto itr = relation.begin(); itr != relation.end(); itr++) {
        if (itr->first.find(i) != itr->first.end() && itr->second) {
          count[i]++;
        }
      }
    }

    cout << *max_element(count.begin(), count.end()) << endl;
  }
}