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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define debug(x) std::cerr << #x << " = " << (x) << std::endl
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;
const int MAXN = 25;

map<PII, int> pos;

int n, ans;
int x[MAXN + 5], y[MAXN + 5];
bool vis[MAXN + 5];
int dp[70000], cnt[70000][400];

int gcd(int x, int y) {
  if (y == 0)
    return x;
  else
    return gcd(y, x % y);
}

PII solve(int x_1, int x_2, int y_1, int y_2) {
  int dx = x_1 - x_2;
  int dy = y_1 - y_2;
  if (dx == 0) {
    return PII(-1, 0);
  } else if (dy == 0) {
    return PII(0, -1);
  } else if (dx < 0 && dy > 0) {
    int Gcd = gcd(-dx, dy);
    dx /= Gcd;
    dy /= Gcd;
  } else if (dx > 0 && dy < 0) {
    int Gcd = gcd(dx, -dy);
    dx = -(dx / Gcd);
    dy = -(dy / Gcd);
  } else {
    dx = abs(dx), dy = abs(dy);
    int Gcd = gcd(dx, dy);
    dx /= Gcd;
    dy /= Gcd;
  }
  return PII(dx, dy);
}

int main() {
  scanf("%d", &n);
  int ans = 0;
  for (int i = 1; i <= n; i++)
    scanf("%d %d", &x[i], &y[i]);
  int tot = 0;
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++) {
      PII tmp = solve(x[i], x[j], y[i], y[j]);
      if (!pos[tmp])
        pos[tmp] = ++tot;
    }
  for (int i = 0; i < (1 << n); i++) {
    int cnt1 = 0;
    for (int j = 1; j <= n; j++)
      vis[j] = 0;
    for (int j = 0; j < n; j++)
      if (i & (1 << j))
        vis[j + 1] = 1, cnt1++;
    if (!(cnt1 & 1)) {
      for (int v1 = 1; v1 <= n; v1++)
        for (int v2 = v1 + 1; v2 <= n; v2++)
          if (!vis[v1] && !vis[v2]) {
            int p = i;
            p |= (1 << (v1 - 1));
            p |= (1 << (v2 - 1));
            int c = pos[solve(x[v1], x[v2], y[v1], y[v2])];
            if (dp[i] + cnt[i][c] >= dp[p]) {
              for (int r = 1; r <= tot; r++)
                cnt[p][r] = cnt[i][r];
              cnt[p][c] += 1;
              dp[p] = dp[i] + cnt[i][c];
            }
          }
    }
  }
  printf("%d\\n", dp[(1 << n) - 1]);
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int inf = 1e9 + 3;
const double eps = 1e-10;
template <class T> inline void read(T &x) {
  int t;
  bool flag = false;
  while ((t = getchar()) != '-' && (t < '0' || t > '9'))
    ;
  if (t == '-')
    flag = true, t = getchar();
  x = t - '0';
  while ((t = getchar()) >= '0' && t <= '9')
    x = x * 10 + t - '0';
  if (flag)
    x = -x;
}
double k[350];
int cnt;
vector<int> vertex[350];
int inlinex(double kk) {
  for (int i = 0; i < cnt; i++) {
    if (fabs(k[i] - kk) < eps)
      return i;
  }
  return cnt;
}
int main() {
  int n, use[20] = {}, maxtt = 88, sum = 0, maxpos;
  double x[20], y[20];
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> x[i] >> y[i];
  while (maxtt > 1) {
    maxtt = 0;
    maxpos = -1;
    for (int i = 0; i < cnt; i++)
      vertex[i].clear();
    cnt = 0;
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        if (use[i] || use[j])
          continue;
        else {
          int nb = inlinex((x[i] - x[j]) / (y[i] - y[j]));
          if (nb == cnt) {
            k[cnt] = (x[i] - x[j]) / (y[i] - y[j]);
            cnt++;
          }
          vertex[nb].push_back(i);
          vertex[nb].push_back(j);
        }
      }
    }
    for (int i = 0; i < cnt; i++) {
      if (vertex[i].size() / 2 > maxtt) {
        maxtt = vertex[i].size() / 2;
        maxpos = i;
      }
    }
    sum = sum + maxtt * (maxtt - 1) / 2;
    for (int i = 0; i < vertex[maxpos].size(); i++)
      use[vertex[maxpos][i]] = 1;
  }
  cout << sum << endl;
  return 0;
}