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

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define DBG cerr << '!' << endl;
#define REP(i, n) for (int(i) = (0); (i) < (n); ++i)
#define rep(i, s, g) for (int(i) = (s); (i) < (g); ++i)
#define rrep(i, s, g) for (int(i) = (s); i >= (g); --(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v, n)                                                           \\
  {                                                                            \\
    for (int W = 0; W < (n); W++)                                              \\
      cerr << v[W] << ' ';                                                     \\
    cerr << endl << endl;                                                      \\
  }
#define SHOW2d(v, i, j)                                                        \\
  {                                                                            \\
    for (int aaa = 0; aaa < i; aaa++) {                                        \\
      for (int bbb = 0; bbb < j; bbb++)                                        \\
        cerr << v[aaa][bbb] << ' ';                                            \\
      cerr << endl;                                                            \\
    }                                                                          \\
    cerr << endl;                                                              \\
  }
#define ALL(v) v.begin(), v.end()
#define Decimal fixed << setprecision(10)

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

#define EPS 1e-6

vector<pair<int, int>> v;
vector<pair<int, int>> p(20);
int n;
int ans;
int comb[10][10];

bool equal(double a, double b) { return ((abs(a - b) < EPS) ? true : false); }

void check() {
  vector<double> tmp;
  REP(i, n / 2) {
    int j = i * 2;
    pair<double, double> a, b, c;
    a = p[j];
    b = p[j + 1];
    c.FI = a.FI - b.FI;
    c.SE = a.SE - b.SE;
    double in = 1000000;
    if (c.SE != 0)
      in = c.FI / c.SE;
    tmp.PB(in);
  }
  sort(ALL(tmp));
  int ret = 0;
  REP(i, tmp.size()) {
    int cou = 0;
    while (i < tmp.size() - 1 && equal(tmp[i], tmp[i + 1])) {
      i++;
      cou++;
    }
    if (cou)
      ret += comb[cou + 1][2];
  }
  ans = max(ans, ret);
}

void dfs(int num, int memo) {
  if (num <= 1) {
    check();
    return;
  }
  //	cout << "!" << endl;
  int tmp = 0;
  while (memo & (1 << tmp))
    tmp++;
  p[n - num] = v[tmp];
  memo |= (1 << tmp);

  for (int i = tmp + 1; i < n; i++) {
    //		cout << "!!" << endl;
    if (!(memo & (1 << i))) {
      //			cout << "!!!" << endl;
      p[n - num + 1] = v[i];
      //			SHOW1d(ME,n);
      dfs(num - 2, memo | (1 << i));
    }
  }
}

int main() {
  REP(i, 10) comb[i][i] = comb[i][0] = 1;
  REP(i, 10) {
    for (int j = 1; j < i; j++)
      comb[i][j] = comb[i - 1][j] + comb[i - 1][j - 1];
  }

  //	SHOW2d(comb,8,8);

  cin >> n;
  REP(i, n) {
    int a, b;
    cin >> a >> b;
    v.PB(MP(a, b));
  }

  dfs(n, 0);

  cout << ans << endl;

  return 0;
}

Error: 0
1 0 0 0 0 0 0 0 
1 1 0 0 0 0 0 0 
1 2 1 0 0 0 0 0 
1 3 3 1 0 0 0 0 
1 4 6 4 1 0 0 0 
1 5 10 10 5 1 0 0 
1 6 15 20 15 6 1 0 
1 7 21 35 35 21 7 1 



Fixed submission:

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define DBG cerr << '!' << endl;
#define REP(i, n) for (int(i) = (0); (i) < (n); ++i)
#define rep(i, s, g) for (int(i) = (s); (i) < (g); ++i)
#define rrep(i, s, g) for (int(i) = (s); i >= (g); --(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v, n)                                                           \\
  {                                                                            \\
    for (int W = 0; W < (n); W++)                                              \\
      cerr << v[W] << ' ';                                                     \\
    cerr << endl << endl;                                                      \\
  }
#define SHOW2d(v, i, j)                                                        \\
  {                                                                            \\
    for (int aaa = 0; aaa < i; aaa++) {                                        \\
      for (int bbb = 0; bbb < j; bbb++)                                        \\
        cerr << v[aaa][bbb] << ' ';                                            \\
      cerr << endl;                                                            \\
    }                                                                          \\
    cerr << endl;                                                              \\
  }
#define ALL(v) v.begin(), v.end()
#define Decimal fixed << setprecision(10)

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

#define EPS 1e-6

vector<pair<int, int>> v;
int n;
int ans;
int comb[10][10];

bool equal(pair<double, double> a, pair<double, double> b) {
  return ((abs(a.FI - b.FI) < EPS && abs(a.SE - b.SE) < EPS) ? true : false);
}

void check(vector<pair<int, int>> p) {
  vector<pair<double, double>> tmp;
  REP(i, p.size() / 2) {
    int j = i * 2;
    pair<double, double> a, b, c;
    a = p[j];
    b = p[j + 1];
    c.FI = a.FI - b.FI;
    c.SE = a.SE - b.SE;
    double l = sqrt(c.FI * c.FI + c.SE * c.SE);
    c.FI /= l;
    c.SE /= l;
    if (c.FI < 0) {
      c.FI = -(c.FI);
      c.SE = -(c.SE);
    }
    tmp.PB(c);
  }

  int ret = 0;
  REP(i, tmp.size()) {
    int cou = 0;
    while (i < tmp.size() - 1 && equal(tmp[i], tmp[i + 1])) {
      i++;
      cou++;
    }
    if (cou)
      ret += comb[cou + 1][2];
  }
  ans = max(ans, ret);
}

void dfs(int num, vector<bool> memo, vector<pair<int, int>> p) {
  if (num <= 1) {
    check(p);
    return;
  }

  int tmp = 0;
  while (memo[tmp])
    tmp++;
  p.PB(v[tmp]);
  memo[tmp] = true;

  for (int i = tmp + 1; i < n; i++) {
    if (!memo[i]) {
      vector<pair<int, int>> P = p;
      vector<bool> ME = memo;
      P.PB(v[i]);
      ME[i] = true;
      //			SHOW1d(ME,n);
      dfs(num - 2, ME, P);
    }
  }
}

int main() {
  REP(i, 10) comb[i][i] = comb[i][0] = 1;
  REP(i, 10) {
    for (int j = 1; j < i; j++)
      comb[i][j] = comb[i - 1][j] + comb[i - 1][j - 1];
  }

  SHOW2d(comb, 8, 8);

  cin >> n;
  REP(i, n) {
    int a, b;
    cin >> a >> b;
    v.PB(MP(a, b));
  }

  vector<bool> memo(16);
  vector<pair<int, int>> p;
  dfs(n, memo, p);

  cout << ans << endl;

  return 0;
}