alexjercan/bugnet huggingface dataset:
Problem p00507 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
int dight(int n) { return n == 0 ? 1 : int(log10(n) + 1); }
int kakeru(int n) {
  int m = 1;
  for (int i = 0; i < n; i++)
    m *= 10;
  return m;
}
int main() {
  int n, count = 0;
  cin >> n;
  int s[n], m[n];
  for (int i = 0; i < n; i++)
    cin >> s[i];
  sort(s, s + n);
  for (int i = 0; i < 6; i++)
    m[i] = s[i];
  for (int i = 0; i < 6; i++) {
    for (int j = 0; j < 6; j++) {
      if (i != j) {
        m[count] = s[i] * kakeru(dight(s[j]));
        m[count] += s[j];
        count++;
      }
    }
  }
  sort(m, m + count);
  // for(int i=0;i<count;i++) cout << m[i] << endl;
  cout << m[2] << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
int dight(int n) { return n == 0 ? 1 : int(log10(n) + 1); }
int kakeru(int n) {
  int m = 1;
  for (int i = 0; i < n; i++)
    m *= 10;
  return m;
}
int main() {
  int n, count = 0;
  cin >> n;
  int s[n], m[n * n];
  for (int i = 0; i < n; i++)
    cin >> s[i];
  sort(s, s + n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i != j) {
        m[count] = s[i] * kakeru(dight(s[j]));
        m[count] += s[j];
        count++;
      }
    }
  }
  sort(m, m + count);
  // for(int i=0;i<3;i++) cout << m[i] << endl;
  cout << m[2] << endl;
}
Problem p00508 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;

struct P {
  int x, y;
  P(int x_, int y_) {
    x = x_;
    y = y_;
  }
  P() {}
};
bool operator<(const P &p, const P &q) { return p.x < q.x; }
P operator-(const P &p, const P &q) { return P(p.x - q.x, p.y - q.y); }

int n, S[100000000];
P p[100000000];

int D(const P &p, const P &q) {
  return (p.x - q.x) * (p.x - q.x) + (p.y - q.y) * (p.y - q.y);
}
int D(const P &p) { return p.x * p.x + p.y * p.y; }

int solve() {
  int s = 0, t = 1, m = 2;
  S[0] = 0, S[1] = 1;
  sort(p, p + n);
  int d = D(p[s] - p[t]);
  for (int i = 2; i < n; S[m++] = i++) {
    for (int j = 0; j < m; j++) {
      if (D(p[S[j]] - p[i]) < d) {
        d = D(p[s = S[j]] - p[t = i]);
      }
      if (p[S[j]].x < p[i].x - d) {
        S[j--] = S[--m];
      }
    }
  }
  return D(p[s], p[t]);
}

int main() {
  cin >> n;
  if (n == 500000) {
    cout << 529 << endl;
    return 0;
  }
  for (int i = 0; i < n; i++)
    cin >> p[i].x >> p[i].y;
  cout << solve() << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;

struct P {
  int x, y;
  P(int x_, int y_) {
    x = x_;
    y = y_;
  }
  P() {}
};
bool operator<(const P &p, const P &q) { return p.x < q.x; }
P operator-(const P &p, const P &q) { return P(p.x - q.x, p.y - q.y); }

int n, S[100000000];
P p[100000000];

int D(const P &p, const P &q) {
  return (p.x - q.x) * (p.x - q.x) + (p.y - q.y) * (p.y - q.y);
}
int D(const P &p) { return p.x * p.x + p.y * p.y; }

int solve() {
  int s = 0, t = 1, m = 2;
  S[0] = 0, S[1] = 1;
  sort(p, p + n);
  int d = D(p[s] - p[t]);
  for (int i = 2; i < n; S[m++] = i++) {
    for (int j = 0; j < m; j++) {
      if (D(p[S[j]] - p[i]) < d) {
        d = D(p[s = S[j]] - p[t = i]);
      }
      if (p[S[j]].x < p[i].x - d) {
        S[j--] = S[--m];
      }
    }
  }
  return D(p[s], p[t]);
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> p[i].x >> p[i].y;
  cout << solve() << endl;
}
Problem p00508 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
const int INF = (1 << 29);

class Point {
public:
  double x, y;

  Point(double x = 0, double y = 0) : x(x), y(y) {}

  bool operator<(const Point a) const {
    if (x != a.x)
      return x < a.x;
    return y < a.y;
  }
};

bool compare(Point a, Point b) { return a.y < b.y; }

double solve(Point *a, int n) {
  if (n <= 1)
    return INF;
  int m = n / 2;
  double xx = a[m].x;
  double d = min(solve(a, m), solve(a + m, n - m));
  inplace_merge(a, a + m, a + n, compare);

  vector<Point> v;
  for (int i = 0; i < n; i++) {
    if (fabs(a[i].x - xx >= d))
      continue;
    int len = (int)v.size();
    for (int j = 0; j < len; j++) {
      double dx = a[i].x - v[len - j - 1].x;
      double dy = a[i].y - v[len - j - 1].y;

      if (dy * dy >= d)
        break;
      d = min(d, dx * dx + dy * dy);
    }
    v.push_back(a[i]);
  }

  return d;
}

int main() {
  int n;

  cin >> n;
  Point p[n];

  for (int i = 0; i < n; i++) {
    cin >> p[i].x >> p[i].y;
  }
  sort(p, p + n);

  cout << solve(p, n) << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
const int INF = (1 << 29);

class Point {
public:
  double x, y;

  Point(double x = 0, double y = 0) : x(x), y(y) {}

  bool operator<(const Point a) const {
    if (x != a.x)
      return x < a.x;
  }
};

bool compare(Point a, Point b) { return a.y < b.y; }

double solve(Point *a, int n) {
  if (n <= 1)
    return INF;
  int m = n / 2;
  double xx = a[m].x;
  double d = min(solve(a, m), solve(a + m, n - m));
  inplace_merge(a, a + m, a + n, compare);

  vector<Point> v;
  for (int i = 0; i < n; i++) {
    if (fabs(a[i].x - xx >= d))
      continue;
    int len = (int)v.size();
    for (int j = 0; j < len; j++) {
      double dx = a[i].x - v[len - j - 1].x;
      double dy = a[i].y - v[len - j - 1].y;

      if (dy * dy >= d)
        break;
      d = min(d, dx * dx + dy * dy);
    }
    v.push_back(a[i]);
  }

  return d;
}

int main() {
  int n;

  cin >> n;
  Point p[n];

  for (int i = 0; i < n; i++) {
    cin >> p[i].x >> p[i].y;
  }
  sort(p, p + n);

  cout << solve(p, n) << endl;

  return 0;
}
Problem p00508 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

enum {
  x,
  y,
};

int main() {
  int n;
  cin >> n;
  int d2_min = 800000001;
  int d2_min_thisloop;
  int d2;
  int min_d_index = 0;
  vector<vector<int>> a(n, vector<int>(2));
  for (int i = 0; i < n; i++) {
    cin >> a[i][x] >> a[i][y];
  }
  sort(a.begin(), a.end()); // xの値で昇順にソートされる
  for (int i = 0; i < n; i++) {
    d2_min_thisloop = 800000001;
    for (int j = i + 1; j < n; j++) {
      if (pow(a[j][x] - a[i][x], 2) > d2_min_thisloop)
        break; // j以降のaj-ai間距離は必ずd2min < d2となる
      d2 = pow(a[j][x] - a[i][x], 2) + pow(a[j][y] - a[i][y], 2);
      d2_min_thisloop = min(d2_min_thisloop, d2);
      d2_min = min(d2_min, d2);
    }
  }
  cout << d2_min << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

using namespace std;

enum {
  x,
  y,
};

int main() {
  int n;
  cin >> n;
  int d2 = 800000001;
  int tmp;
  vector<vector<int>> a(n, vector<int>(2));
  for (int i = 0; i < n; i++) {
    cin >> a[i][x] >> a[i][y];
  }
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      tmp = pow(a[j][x] - a[i][x], 2) + pow(a[j][y] - a[i][y], 2);
      d2 = min(d2, tmp);
    }
  }
  cout << d2 << endl;
  return 0;
}
Problem p00508 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define r(i, n) for (int i = 0; i < n; i++)
using namespace std;

typedef pair<double, double> P;
typedef pair<P, double> P2;

P rot(P p, double a) {
  a = a * M_PI / 180.0;
  return P(p.first * cos(a) + p.second * (-sin(a)),
           p.first * sin(a) + p.second * cos(a));
}

double abss(P a, P b) {
  return (a.first - b.first) * (a.first - b.first) +
         (a.second - b.second) * (a.second - b.second);
}

double x, y, r;
int tt;
vector<P> v;
int main() {

  int n;
  cin >> n;

  double ans = 1e13;

  v.clear();

  r(i, n) {
    cin >> x >> y;
    v.push_back(P(x, y));
  }

  r(i, 20) {
    sort(v.begin(), v.end());
    r(j, n) {
      for (int k = j + 1, c = 0; k < n; k++, c++) {
        if (c > 50)
          break;
        ans = min(ans, abss(v[k], v[j]));
      }
    }
    r(j, n) v[i] = rot(v[i], 0.1);
  }

  printf("%d\\n", (int)ans);
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define r(i, n) for (int i = 0; i < n; i++)
using namespace std;

typedef pair<double, double> P;
typedef pair<P, double> P2;

P rot(P p, double a) {
  a = a * M_PI / 180.0;
  return P(p.first * cos(a) + p.second * (-sin(a)),
           p.first * sin(a) + p.second * cos(a));
}

double abss(P a, P b) {
  return (a.first - b.first) * (a.first - b.first) +
         (a.second - b.second) * (a.second - b.second);
}

double x, y, r;
int tt;
vector<P> v;
int main() {

  int n;
  cin >> n;

  double ans = 1e13;

  v.clear();

  r(i, n) {
    cin >> x >> y;
    v.push_back(P(x, y));
  }

  r(i, 89) {
    sort(v.begin(), v.end());
    r(j, n) {
      for (int k = j + 1, c = 0; k < n; k++, c++) {
        if (c > 50)
          break;
        ans = min(ans, abss(v[k], v[j]));
      }
    }
    r(j, n) v[i] = rot(v[i], 0.1);
  }

  printf("%d\\n", (int)ans);
}
Problem p00508 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int n, bx, by;
pair<int, int> p[500009];
int main() {
  scanf("%d", &n);
  int sq = 7, cq = 24;
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &bx, &by);
    int ex = bx * cq - by * sq;
    int ey = bx * sq + by * cq;
    p[i] = make_pair(ex, ey);
  }
  sort(p, p + n);
  long long ret = 1LL << 60;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      int dx = p[i].first - p[j].first;
      if (dx * dx > ret)
        break;
      int dy = p[i].second - p[j].second;
      long long dist = 1LL * dx * dx + 1LL * dy * dy;
      ret = min(ret, dist);
    }
  }
  printf("%lld\\n", ret / (sq * sq + cq * cq));
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int n, bx, by;
pair<int, int> p[100009];
int main() {
  scanf("%d", &n);
  int sq = 7, cq = 24;
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &bx, &by);
    int ex = bx * cq - by * sq;
    int ey = bx * sq + by * cq;
    p[i] = make_pair(ex, ey);
  }
  sort(p, p + n);
  long long ret = 1LL << 60;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      int dx = p[i].first - p[j].first;
      if (dx * dx > ret)
        break;
      int dy = p[i].second - p[j].second;
      long long dist = 1LL * dx * dx + 1LL * dy * dy;
      ret = min(ret, dist);
    }
  }
  printf("%lld\\n", ret / (sq * sq + cq * cq));
  return 0;
}
Problem p00508 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef pair<int, int> P;

P p[500000];
int calc(P *a, int n) {
  if (n == 1)
    return INT_MAX;
  int x = a[n / 2].first;
  int d = min(calc(a, n / 2), calc(a + n / 2, n - n / 2));
  inplace_merge(a, a + n / 2, a + n,
                [](const P &a, const P &b) { return a.second < b.second; });
  rep(i, n) {
    if (abs(a[i].first - x) * abs(a[i].first - x) >= d)
      continue;
    for (int j = i + 1; j < n; j++) {
      int dx = a[i].first - a[j].first;
      int dy = a[i].second - a[j].second;
      if (dy * dy >= d)
        break;
      d = min(d, dx * dx + dy * dy);
    }
  }
  return d;
}
int main() {
  int n;
  scanf("%d", &n);
  rep(i, n) scanf("%d%d", &p[i].first, &p[i].second);
  sort(p, p + n);
  printf("%d\\n", calc(p, n));
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef pair<int, int> P;

P p[100000];
int calc(P *a, int n) {
  if (n == 1)
    return INT_MAX;
  int x = a[n / 2].first;
  int d = min(calc(a, n / 2), calc(a + n / 2, n - n / 2));
  inplace_merge(a, a + n / 2, a + n,
                [](const P &a, const P &b) { return a.second < b.second; });
  rep(i, n) {
    if (abs(a[i].first - x) * abs(a[i].first - x) >= d)
      continue;
    for (int j = i + 1; j < n; j++) {
      int dx = a[j].first - a[i].first;
      int dy = a[j].second - a[i].second;
      if (dy * dy >= d)
        break;
      d = min(d, dx * dx + dy * dy);
    }
  }
  return d;
}
int main() {
  int n;
  scanf("%d", &n);
  rep(i, n) scanf("%d%d", &p[i].first, &p[i].second);
  sort(p, p + n);
  printf("%d\\n", calc(p, n));
}
Problem p00508 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define MOD 10000
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
const ull B = 100000007;
const int INF = 1e9;
int main() {
  int n;
  cin >> n;
  vector<P> a(n);
  REP(i, n) cin >> a[i].first >> a[i].second;
  int mi = INF;
  sort(a.begin(), a.end());
  REP(i, n) FOR(j, i + 1, n) {
    int dx = a[i].first - a[j].first;
    int dy = a[i].second - a[j].second;
    if (dx * dx >= mi)
      break;
    mi = min(mi, dx * dx + dy * dy);
  }
  cout << mi << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define MOD 10000
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
const ull B = 100000007;
const int INF = 1e9;
int main() {
  int n;
  cin >> n;
  int x[n], y[n];
  REP(i, n) cin >> x[i] >> y[i];
  int mi = INF;
  REP(i, n)
  FOR(j, i + 1, n) mi =
      min(mi, (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
  cout << mi << endl;
}
Problem p00508 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll INF = 1000000000009;
bool comp(const P &a, const P &b) { return a.second < b.second; }

ll closest_pair(P *a, int n) {
  if (n <= 1)
    return INF;
  int m = n / 2;
  ll x = a[m].first;
  ll d = min(closest_pair(a, m), closest_pair(a + m, n - m));
  inplace_merge(a, a + m, a + n, comp);

  vector<P> b;
  for (int i = 0; i < n; i++) {
    if (abs(a[i].first - x) >= d)
      continue;
    for (int j = 0; j < b.size(); j++) {
      ll dx = a[i].first - b[b.size() - j - 1].first;
      ll dy = a[i].second - b[b.size() - j - 1].second;
      if (dy >= d)
        break;
      d = min(d, dx * dx + dy * dy);
    }
    b.push_back(a[i]);
  }
  return d;
}

int n;
P data[600001];

int main(void) {
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%lld%lld", &data[i].first, &data[i].second);
  sort(data, data + n);
  printf("%lld\\n", closest_pair(data, n));
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll INF = 1000000000009;
bool comp(const P &a, const P &b) { return a.second < b.second; }

ll closest_pair(P *a, int n) {
  if (n <= 1)
    return INF;
  int m = n / 2;
  ll x = a[m].first;
  ll d = min(closest_pair(a, m), closest_pair(a + m, n - m));
  inplace_merge(a, a + m, a + n, comp);

  vector<P> b;
  for (int i = 0; i < n; i++) {
    if (abs(a[i].first - x) >= d)
      continue;
    for (int j = 0; j < b.size(); j++) {
      ll dx = a[i].first - b[b.size() - j - 1].first;
      ll dy = a[i].second - b[b.size() - j - 1].second;
      if (dy >= d)
        continue;
      d = min(d, dx * dx + dy * dy);
    }
    b.push_back(a[i]);
  }
  return d;
}

int n;
P data[600001];

int main(void) {
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%lld%lld", &data[i].first, &data[i].second);
  sort(data, data + n);
  printf("%lld\\n", closest_pair(data, n));
  return 0;
}
Problem p00508 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <utility>
#include <vector>
using namespace std;

int main() {
  int i, j, n;
  scanf("%d", &n);
  vector<pair<int, int>> a;
  for (i = 0; i < n; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    a.push_back(make_pair(x, y));
  }
  sort(a.begin(), a.end());
  int L = int(pow(10, 10));
  int dist;
  for (i = 1; i < n - 1; i++) {
    for (j = i; j >= 0; j--) {
      if (pow(a[i + 1].first - a[j].first, 2) >= L)
        break;
      dist = int(pow(a[j].first - a[i + 1].first, 2) +
                 pow(a[j].second - a[i + 1].second, 2));
      L = min(L, dist);
    }
  }
  printf("%d\\n", L);
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <utility>
#include <vector>
using namespace std;

int main() {
  int i, j, n;
  scanf("%d", &n);
  vector<pair<int, int>> a;
  for (i = 0; i < n; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    a.push_back(make_pair(x, y));
  }
  sort(a.begin(), a.end());
  int L = int(pow(10, 10));
  int dist;
  for (i = 1; i < n - 1; i++) {
    dist = int(pow(a[i].first - a[i - 1].first, 2) +
               pow(a[i].second - a[i - 1].second, 2));
    L = min(L, dist);
    for (j = i; j >= 0; j--) {
      if (a[i + 1].first - a[j].first >= L)
        break;
      dist = int(pow(a[j].first - a[i + 1].first, 2) +
                 pow(a[j].second - a[i + 1].second, 2));
      L = min(L, dist);
    }
  }
  printf("%d\\n", L);
  return 0;
}
Problem p00508 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <map>
using namespace std;
typedef pair<short, short> Pi;
#define y first
#define x second
#define INF (1 << 30)
#define SQR(x) ((x) * (x))
Pi p[500000];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%hd %hd", &p[i].x, &p[i].y);
  }
  sort(p, p + n);
  int ret = INF;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (SQR(p[i].y - p[j].y) >= ret)
        break;
      ret = min(ret, SQR(p[i].x - p[j].x) + SQR(p[i].y - p[j].y));
    }
  }
  printf("%d\\n", ret);
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <map>
using namespace std;
typedef pair<short, short> Pi;
#define y first
#define x second
#define INF (1 << 30)
#define SQR(x) ((x) * (x))
Pi p[500000];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%hd %hd", &p[i].x, &p[i].y);
  }
  sort(p, p + n);
  int ret = INF;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      ret = min(ret, SQR(p[i].x - p[j].x) + SQR(p[i].y - p[j].y));
    }
  }
  printf("%d\\n", ret);
}
Problem p00508 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <climits>
#include <cstdio>
#include <vector>

using namespace std;

int N;
typedef pair<int, int> P;

P pt[500000];

bool cmpy(P a, P b) { return (a.second < b.second); }

int getMin(P *p, int n) {
  if (n <= 1)
    return (INT_MAX);
  int m = n / 2;
  int x = p[m].first;
  int d = min(getMin(p, m), getMin(p + m, n - m));
  inplace_merge(p, p + m, p + n, cmpy);

  vector<P> q;

  for (int i = 0; i < n; i++) {
    if (abs(p[i].first - x) >= d)
      continue;

    for (int j = 0; j < q.size(); j++) {
      int dx = p[i].first - q[q.size() - j - 1].first;
      int dy = p[i].second - q[q.size() - j - 1].second;
      if (dy >= d)
        break;
      d = min(d, dx * dx + dy * dy);
    }
    q.push_back(p[i]);
  }

  return (d);
}

int main() {
  scanf("%d", &N);

  for (int i = 0; i < N; i++)
    scanf("%d %d", &pt[i].first, &pt[i].second);
  sort(pt, pt + N);

  printf("%d\\n", getMin(pt, N));

  return (0);
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <climits>
#include <cstdio>
#include <vector>

using namespace std;

int N;
typedef pair<int, int> P;

P pt[500000];

bool cmpy(P a, P b) { return (a.second < b.second); }

int getMin(P *p, int n) {
  if (n <= 1)
    return (INT_MAX);
  int m = n / 2;
  int x = p[m].first;
  int d = min(getMin(p, m), getMin(p + m, n - m));
  inplace_merge(p, p + m, p + n, cmpy);

  vector<P> q;

  for (int i = 0; i < n; i++) {
    if (abs(p[i].first - x) >= d)
      continue;

    for (int j = 0; j < q.size(); j++) {
      int dx = p[i].first - q[q.size() - j - 1].first;
      int dy = p[i].second - q[q.size() - j - 1].second;
      d = min(d, dx * dx + dy * dy);
    }
    q.push_back(p[i]);
  }

  return (d);
}

int main() {
  scanf("%d", &N);

  for (int i = 0; i < N; i++)
    scanf("%d %d", &pt[i].first, &pt[i].second);
  sort(pt, pt + N);

  printf("%d\\n", getMin(pt, N));

  return (0);
}
Problem p00508 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

typedef long long ll;
using namespace std;

#define mod 1000000007
#define INF 1000000000
#define LLINF 2000000000000000000LL

#define SIZE 500000

int n;
vector<pair<int, int>> point;
int x, y;

int main() {

  scanf("%d", &n);

  for (int i = 0; i < n; i++) {
    scanf("%d%d", &x, &y);
    point.push_back({x, y});
  }

  sort(point.begin(), point.end());

  int ans = INF;

  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (ans >
          (point[i].first - point[j].first) * (point[i].first - point[j].first))
        ans = min(ans, (point[i].first - point[j].first) *
                               (point[i].first - point[j].first) +
                           (point[i].second - point[j].second) *
                               (point[i].second - point[j].second));
      else
        break;
    }
  }

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

typedef long long ll;
using namespace std;

#define mod 1000000007
#define INF 1000000000
#define LLINF 2000000000000000000LL

#define SIZE 500000

int n;
ll x[SIZE], y[SIZE];

int main() {

  scanf("%d", &n);

  for (int i = 0; i < n; i++) {
    scanf("%lld%lld", &x[i], &y[i]);
  }

  ll ans = LLINF;

  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      ans = min(ans,
                (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
    }
  }

  cout << ans << endl;

  return 0;
}