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

#include <algorithm>
#include <assert.h>
#include <cassert>
#include <ccomplex>
#include <clocale>
#include <cmath>
#include <complex>
#include <ctype.h>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <locale>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <utility>
#include <valarray>
#include <vector>
#include <wchar.h>

using namespace std;
typedef long long int LL;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(), (c).end())
#define BACKSORT(c) sort((c).begin(), (c).end(), std::greater<LL>())
#define FOR(i, a, b) for (LL i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

int xcomp(vector<int> &a, vector<int> &b) { return a[0] < b[0]; }

int ycomp(vector<int> &a, vector<int> &b) { return a[1] < b[1]; }

#define XSORT(c) sort((c).begin(), (c).end(), xcomp)
#define YSORT(c) sort((c).begin(), (c).end(), ycomp)

#define ALL(x) (x).begin(), (x).end()

int henkan(int a) {
  if (a == 10000) {
    return 199;
  } else {
    return (a + 10000) / 100;
  }
}

LL mod = 1000000007;
int main() {

  int n;
  cin >> n;

  if (n <= 100) {
    vector<vector<int>> v(n, vector<int>(2));
    REP(i, n) { cin >> v[i][0] >> v[i][1]; }
    int min = 1000000000;
    REP(i, n) {
      FOR(j, i + 1, n) {
        int r = (v[i][0] - v[j][0]) * (v[i][0] - v[j][0]) +
                (v[i][1] - v[j][1]) * (v[i][1] - v[j][1]);
        if (r < min) {
          min = r;
        }
      }
    }
    cout << min << endl;
  } else {

    vector<vector<vector<vector<int>>>> v(
        200, vector<vector<vector<int>>>(200, vector<vector<int>>(0)));
    REP(i, n) {
      int a, b;
      cin >> a >> b;
      v[henkan(a)][henkan(b)].push_back({a, b});
    }
    int min = 100000;
    REP(i, 199) {

      REP(j, 199) {
        vector<vector<int>> vv(0);

        vv.insert(vv.end(), v[i][j].begin(), v[i][j].end());
        vv.insert(vv.end(), v[i][j + 1].begin(), v[i][j + 1].end());
        vv.insert(vv.end(), v[i + 1][j].begin(), v[i + 1][j].end());
        vv.insert(vv.end(), v[i + 1][j + 1].begin(), v[i + 1][j + 1].end());

        REP(ii, vv.size()) {
          FOR(jj, ii + 1, vv.size()) {
            int r = (vv[ii][0] - vv[jj][0]) * (vv[ii][0] - vv[jj][0]) +
                    (vv[ii][1] - vv[jj][1]) * (vv[ii][1] - vv[jj][1]);
            if (r < min) {
              min = r;
            }
          }
        }
      }
    }
    cout << min << endl;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <assert.h>
#include <cassert>
#include <ccomplex>
#include <clocale>
#include <cmath>
#include <complex>
#include <ctype.h>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <locale>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <utility>
#include <valarray>
#include <vector>
#include <wchar.h>

using namespace std;
typedef long long int LL;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(), (c).end())
#define BACKSORT(c) sort((c).begin(), (c).end(), std::greater<LL>())
#define FOR(i, a, b) for (LL i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

int xcomp(vector<int> &a, vector<int> &b) { return a[0] < b[0]; }

int ycomp(vector<int> &a, vector<int> &b) { return a[1] < b[1]; }

#define XSORT(c) sort((c).begin(), (c).end(), xcomp)
#define YSORT(c) sort((c).begin(), (c).end(), ycomp)

#define ALL(x) (x).begin(), (x).end()

int henkan(int a) { return (a + 10000) / 100; }

LL mod = 1000000007;
int main() {

  int n;
  cin >> n;

  if (n <= 100) {
    vector<vector<int>> v(n, vector<int>(2));
    REP(i, n) { cin >> v[i][0] >> v[i][1]; }
    int min = 1000000000;
    REP(i, n) {
      FOR(j, i + 1, n) {
        int r = (v[i][0] - v[j][0]) * (v[i][0] - v[j][0]) +
                (v[i][1] - v[j][1]) * (v[i][1] - v[j][1]);
        if (r < min) {
          min = r;
        }
      }
    }
    cout << min << endl;
  } else {

    vector<vector<vector<vector<int>>>> v(
        201, vector<vector<vector<int>>>(201, vector<vector<int>>(0)));
    REP(i, n) {
      int a, b;
      cin >> a >> b;
      v[henkan(a)][henkan(b)].push_back({a, b});
    }
    int min = 1000000000;
    REP(i, 200) {

      REP(j, 200) {
        vector<vector<int>> vv(0);

        vv.insert(vv.end(), v[i][j].begin(), v[i][j].end());
        vv.insert(vv.end(), v[i][j + 1].begin(), v[i][j + 1].end());
        vv.insert(vv.end(), v[i + 1][j].begin(), v[i + 1][j].end());
        vv.insert(vv.end(), v[i + 1][j + 1].begin(), v[i + 1][j + 1].end());

        REP(ii, vv.size()) {
          FOR(jj, i + 1, vv.size()) {
            int r = (vv[i][0] - vv[j][0]) * (vv[i][0] - vv[j][0]) +
                    (vv[i][1] - vv[j][1]) * (vv[i][1] - vv[j][1]);
            if (r < min) {
              min = r;
            }
          }
        }
      }
    }
    cout << min << endl;
  }
}