Problem p03006 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

typedef long long ll;
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define exout(x) printf("%.10f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX_N = 201010;

// 組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX_N; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(ll n, ll k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// 最大公約数
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

ll lcm(ll x, ll y) {
  if (x == 0 || y == 0)
    return 0;
  return (x / gcd(x, y) * y);
}

ll dx[4] = {0, 0, -1, 1};
ll dy[4] = {-1, 1, 0, 0};
char notes[110][10];

// long longしか使わない
// 素数は1より大きい
// lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
// upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
  ll n;
  cin >> n;
  vector<pair<ll, ll>> point;
  rep(i, n) {
    ll x, y;
    cin >> x >> y;
    point.push_back(make_pair(x, y));
  }
  sort(point.begin(), point.end());
  vector<pair<ll, ll>> dist;
  rep(i, n) {
    for (ll j = i + 1; j < n; ++j) {
      ll nx = point[i].first - point[j].first;
      ll ny = point[i].second - point[j].second;
      dist.push_back(make_pair(nx, ny));
    }
  }
  sort(dist.begin(), dist.end());
  ll k = dist.size();
  ll ans = 1;
  ll res = 0;
  ll dx = dist[0].first;
  ll dy = dist[0].second;
  for (ll i = 1; i < k; ++i) {
    if (dist[i].first != dx || dist[i].second != dy) {
      ans = max(ans, res);
      res = 1;
      dx = dist[i].first;
      dy = dist[i].second;
    } else {
      res++;
      ans = max(ans, res);
    }
  }
  cout << n - ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

typedef long long ll;
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define exout(x) printf("%.10f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX_N = 201010;

// 組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX_N; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(ll n, ll k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// 最大公約数
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

ll lcm(ll x, ll y) {
  if (x == 0 || y == 0)
    return 0;
  return (x / gcd(x, y) * y);
}

ll dx[4] = {0, 0, -1, 1};
ll dy[4] = {-1, 1, 0, 0};
char notes[110][10];

// long longしか使わない
// 素数は1より大きい
// lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
// upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
  ll n;
  cin >> n;
  if (n == 1) {
    cout << 1 << endl;
    return 0;
  }
  vector<pair<ll, ll>> point;
  rep(i, n) {
    ll x, y;
    cin >> x >> y;
    point.push_back(make_pair(x, y));
  }
  sort(point.begin(), point.end());
  vector<pair<ll, ll>> dist;
  rep(i, n) {
    for (ll j = i + 1; j < n; ++j) {
      ll nx = point[i].first - point[j].first;
      ll ny = point[i].second - point[j].second;
      dist.push_back(make_pair(nx, ny));
    }
  }
  sort(dist.begin(), dist.end());
  ll k = dist.size();
  ll ans = 1;
  ll res = 0;
  ll dx = dist[0].first;
  ll dy = dist[0].second;
  for (ll i = 1; i < k; ++i) {
    if (dist[i].first != dx || dist[i].second != dy) {
      ans = max(ans, res);
      res = 1;
      dx = dist[i].first;
      dy = dist[i].second;
    } else {
      res++;
      ans = max(ans, res);
    }
  }
  cout << n - ans << endl;
  return 0;
}