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

#include <bits/stdc++.h>
using namespace std;

int x[3000], y[3000];
bool f[5001][5001];

int main() {
  int n;
  while (scanf("%d", &n), n) {
    memset(x, 0, sizeof(x));
    memset(y, 0, sizeof(y));
    memset(f, 0, sizeof(f));

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

    int maxi = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 1; j < n; j++) {
        const int X = abs(x[i] - x[j]);
        const int Y = abs(y[i] - y[j]);

        if (x[i] + Y <= 5000 && y[i] + X <= 5000 && x[j] + Y <= 5000 &&
            y[j] + X <= 5000) {
          if (f[x[i] + Y][y[i] + X] && f[x[j] + Y][y[j] + X]) {
            maxi = max(maxi, X * X + Y * Y);
          }
        }
      }
    }

    printf("%d\\n", maxi);
  }

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int x[3000], y[3000];
bool f[5001][5001];

int main() {
  int n;
  while (scanf("%d", &n), n) {
    memset(x, 0, sizeof(x));
    memset(y, 0, sizeof(y));
    memset(f, 0, sizeof(f));

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

    int maxi = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 1; j < n; j++) {
        const int X = abs(x[i] - x[j]);
        const int Y = abs(y[i] - y[j]);

        if (f[x[i] + Y][y[i] + X] && f[x[j] + Y][y[j] + X]) {
          maxi = max(maxi, X * X + Y * Y);
        }
      }
    }

    printf("%d\\n", maxi);
  }

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

#include <iostream>

#define N 3000
#define S 5001
int px[N], py[N];
int n;
char pillar[S][S];

void init() {
  int i, j;
  for (i = 0; i < S; i++) {
    for (j = 0; j < S; j++) {
      pillar[i][j] = 0;
    }
  }
  return;
}

int input() {
  int i, x, y;
  init();
  std::cin >> n;
  for (i = 0; i < n; i++) {
    std::cin >> x >> y;
    pillar[x][y] = 1;
    px[i] = x;
    py[i] = y;
  }
  return n;
}

int func() {
  int area = 0, i, j, dx, dy, p3x, p3y, p4x, p4y;
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      if (i == j) {
        continue;
      }
      // std::cout << i << "," << j << std::endl;
      dx = px[i] - px[j];
      dy = py[i] - py[j];
      p3x = px[j] + dy;
      p3y = py[j] - dx;
      p4x = px[i] + dy;
      p4y = py[i] - dx;
      // std::cout << px[i] << "," << py[i] << ":" << px[j] << "," << py[j] <<
      // ":"; std::cout << p3x << "," << p3y << ":" << p4x << "," << p4y <<
      // std::endl;
      if (p3x < 0 || p3y < 0 || p4x < 0 || p4y < 0) {
        continue;
      }
      if (p3x >= S || p3y >= S || p4x >= S || p4y >= S) {
        continue;
      }
      if (pillar[p3x][p3y] == 1 && pillar[p4x][p4y] == 1) {
        int s = dx * dx + dy * dy;
        area = (s > area ? s : area);
      }
    }
  }
  return area;
}

int main() {
  while (input() > 0) {
    std::cout << func() << std::endl;
  }
  return 0;
}

Error: MLE

Fixed submission:

#include <iostream>

#define N 3000
#define S 5001
int px[N], py[N];
int n;
int pillar[S][S];

void init() {
  int i, j;
  for (i = 0; i < S; i++) {
    for (j = 0; j < S; j++) {
      pillar[i][j] = 0;
    }
  }
  return;
}

int input() {
  int i, x, y;
  init();
  std::cin >> n;
  for (i = 0; i < n; i++) {
    std::cin >> x >> y;
    pillar[x][y] = 1;
    px[i] = x;
    py[i] = y;
  }
  return n;
}

int func() {
  int area = 0, i, j, dx, dy, p3x, p3y, p4x, p4y;
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      if (i == j) {
        continue;
      }
      // std::cout << i << "," << j << std::endl;
      dx = px[i] - px[j];
      dy = py[i] - py[j];
      p3x = px[j] + dy;
      p3y = py[j] - dx;
      p4x = px[i] + dy;
      p4y = py[i] - dx;
      // std::cout << px[i] << "," << py[i] << ":" << px[j] << "," << py[j] <<
      // ":"; std::cout << p3x << "," << p3y << ":" << p4x << "," << p4y <<
      // std::endl;
      if (p3x < 0 || p3y < 0 || p4x < 0 || p4y < 0) {
        continue;
      }
      if (p3x >= S || p3y >= S || p4x >= S || p4y >= S) {
        continue;
      }
      if (pillar[p3x][p3y] == 1 && pillar[p4x][p4y] == 1) {
        int s = dx * dx + dy * dy;
        area = (s > area ? s : area);
      }
    }
  }
  return area;
}

int main() {
  while (input() > 0) {
    std::cout << func() << std::endl;
  }
  return 0;
}
Problem p00441 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <complex>
#include <iostream>
#include <vector>

using namespace std;

#define loop(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rep(i, b) loop(i, 0, b)
#define all(c) (c).begin(), (c).end()

typedef complex<int> P;

auto compfn = [](const P &p, const P &q) -> bool {
  return p.real() != q.real() ? p.real() < q.real() : p.imag() < q.imag();
};

int main() {
  int n;
  while (cin >> n, n) {
    vector<P> v(n);
    rep(i, n) {
      int x, y;
      cin >> x >> y;
      v[i] = P(x, y);
    }
    int ans = 0;
    sort(all(v), compfn);
    rep(i, n) rep(j, i) {
      P &p = v[i], &q = v[j];
      P ii = P(0, 1);
      P a = p + (q - p) * ii, b = q + (q - p) * ii;
      if ((binary_search(all(v), a, compfn) &&
           binary_search(all(v), b, compfn))) {
        ans = max(norm(a - b), ans);
      }
    }
    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <complex>
#include <iostream>
#include <vector>

using namespace std;

#define loop(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rep(i, b) loop(i, 0, b)
#define all(c) (c).begin(), (c).end()

typedef complex<long long> P;

auto compfn = [](const P &p, const P &q) -> bool {
  return p.real() != q.real() ? p.real() < q.real() : p.imag() < q.imag();
};

int main() {
  int n;
  while (cin >> n) {
    vector<P> v(n);
    rep(i, n) {
      int x, y;
      cin >> x >> y;
      v[i] = P(x, y);
    }
    long long ans = 0;
    sort(all(v), compfn);
    rep(i, n) rep(j, i) {
      cout << i << " " << j << " " << endl;
      P &p = v[i], &q = v[j];
      P ii = P(0, 1);
      P a = p + (q - p) * ii, b = q + (p - q) * (-ii);
      auto bs = [&v](const P &p) -> bool {
        return binary_search(all(v), p, compfn);
      };
      if ((bs(a) && bs(b))) {
        ans = max(norm(p - q), ans);
      }
    }
    cout << ans << endl;
  }
}
Problem p00441 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define P pair<int, int>
using namespace std;

P b[3000];
int main() {
  int a;
  while (cin >> a, a) {
    for (int c = 0; c < a; c++) {
      int d, e;
      scanf("%d%d", &d, &e);
      b[c] = P(d, e);
    }
    sort(b, b + a);
    int MAX = 0;
    for (int e = 0; e < a; e++) {
      for (int f = e + 1; f < a; f++) {
        int xi = b[e].first, xj = b[f].first, yi = b[e].second,
            yj = b[f].second;
        int k = (xi - xj) * (xi - xj) + (yi - yj) * (yi - yj);
        if (k <= MAX)
          continue;
        if (binary_search(b, b + a, P(xj - yj + yi, yj + xj - xi))) {
          if (binary_search(b, b + a, P(xi - yj + yi, yi + xj - xi))) {
            MAX = k;
          }
        }
      }
    }
    printf("%d\\n", MAX);
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define P pair<int, int>
using namespace std;

P b[3000];
int main() {
  int a;
  while (cin >> a, a) {
    for (int c = 0; c < a; c++) {
      scanf("%d%d", &b[c].first, &b[c].second);
    }
    sort(b, b + a);
    int MAX = 0;
    for (int e = 0; e < a; e++) {
      for (int f = e + 1; f < a; f++) {
        int xi = b[e].first, xj = b[f].first, yi = b[e].second,
            yj = b[f].second;
        int k = (xi - xj) * (xi - xj) + (yi - yj) * (yi - yj);
        if (k <= MAX)
          continue;
        if (find(b, b + a, P(xj - yj + yi, yj + xj - xi)) != b + a) {
          if (find(b, b + a, P(xi - yj + yi, yi + xj - xi)) != b + a) {
            MAX = k;
          }
        }
      }
    }
    cout << MAX << endl;
  }
}
Problem p00441 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
int n;
int x[3000], y[3000];
bool f[5001][5001];
int i, j;
int a, b, p, q, r, s;
int m;

int max(int c, int d) {
  if (c >= d)
    return c;
  else
    return d;
}

int main() {
  while (1) {
    scanf("%d", &n);
    if (n == 0)
      return 0;
    m = 0;
    for (i = 0; i <= 5001; i++)
      for (j = 0; j <= 5001; j++)
        f[i][j] = false;
    for (i = 0; i < n; i++) {
      scanf("%d %d", &x[i], &y[i]);
      f[x[i]][y[i]] = true;
    }
    for (i = 0; i < n - 1; i++)
      for (j = i + 1; j < n; j++) {
        a = x[i] - x[j];
        b = y[i] - y[j];
        if ((x[i] + b >= 0 && y[i] - a >= 0 && x[j] + b >= 0 && y[j] - a >= 0 &&
             x[i] + b <= 5000 && y[i] - a <= 5000 && x[j] + b <= 5000 &&
             y[j] - a <= 5000 && f[x[i] + b][y[i] - a] &&
             f[x[j] + b][y[j] - a]) ||
            (x[i] - b >= 0 && y[i] + a >= 0 && x[j] - b >= 0 && y[j] + a >= 0 &&
             x[i] - b <= 5000 && y[i] + a <= 5000 && x[j] - b <= 5000 &&
             y[j] + a <= 5000 && f[x[i] - b][y[i] + a] &&
             f[x[j] - b][y[j] + a]))
          m = max(m, a * a + b * b);
      }
    printf("%d\\n", m);
  }
}

Error: TLE

Fixed submission:

#include <stdio.h>
int n;
int x[3000], y[3000];
bool f[5001][5001];
int i, j;
int a, b, p, q, r, s;
int m;

int max(int c, int d) {
  if (c >= d)
    return c;
  else
    return d;
}

int main() {
  while (1) {
    scanf("%d", &n);
    if (n == 0)
      return 0;
    m = 0;
    for (i = 0; i <= 5001; i++)
      for (j = 0; j <= 5001; j++)
        f[i][j] = false;
    for (i = 0; i < n; i++) {
      scanf("%d %d", &x[i], &y[i]);
      f[x[i]][y[i]] = true;
    }
    for (i = 0; i < n - 1; i++)
      for (j = i + 1; j < n; j++) {
        a = x[i] - x[j];
        b = y[i] - y[j];
        if ((x[i] + b >= 0 && y[i] - a >= 0 && x[j] + b >= 0 && y[j] - a >= 0 &&
             f[x[i] + b][y[i] - a] && f[x[j] + b][y[j] - a]) ||
            (x[i] - b >= 0 && y[i] + a >= 0 && x[j] - b >= 0 && y[j] + a >= 0 &&
             f[x[i] - b][y[i] + a] && f[x[j] - b][y[j] + a]))
          m = max(m, a * a + b * b);
      }
    printf("%d\\n", m);
  }
}
Problem p00441 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int n;
bool p[5001][5001];
bool c(int a) { return 0 <= a && a <= 5000; }
int main() {
  while (cin >> n && n) {
    int x[5001], y[5001], an = 0;
    for (int i = 0; i < n; i++)
      cin >> x[i] >> y[i], p[x[i]][y[i]] = 1;
    for (int i = 0; i < n; i++)
      for (int j = i; j < n; j++) {
        int dx = x[i] - x[j], dy = y[i] - y[j];
        int x1 = x[i] - dy, y1 = y[i] + dx, x2 = x[j] - dy, y2 = y[j] + dx;
        int x3 = x[i] - dy, y3 = y[i] + dx, x4 = x[j] + dy, y4 = y[j] - dx;
        if (c(x1) && c(y1) && p[x1][y1] && c(x2) && c(y2) && p[x2][y2])
          an = max(an, dx * dx + dy * dy);
        if (c(x3) && c(y3) && p[x3][y3] && c(x4) && c(y4) && p[x4][y4])
          an = max(an, dx * dx + dy * dy);
      }
    cout << an << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
bool c(int a) { return 0 <= a && a <= 5000; }
int main() {
  int n;
  bool p[5001][5001] = {};
  while (cin >> n && n) {
    int x[5001], y[5001], an = 0;
    for (int i = 0; i < n; i++)
      cin >> x[i] >> y[i], p[x[i]][y[i]] = 1;
    for (int i = 0; i < n; i++)
      for (int j = i; j < n; j++) {
        int dx = x[i] - x[j], dy = y[i] - y[j];
        int x1 = x[i] - dy, y1 = y[i] + dx, x2 = x[j] - dy, y2 = y[j] + dx;
        int x3 = x[i] - dy, y3 = y[i] + dx, x4 = x[j] + dy, y4 = y[j] - dx;
        if (c(x1) && c(y1) && p[x1][y1] && c(x2) && c(y2) && p[x2][y2])
          an = max(an, dx * dx + dy * dy);
        if (c(x3) && c(y3) && p[x3][y3] && c(x4) && c(y4) && p[x4][y4])
          an = max(an, dx * dx + dy * dy);
      }
    cout << an << endl;
  }
  return 0;
}
Problem p00441 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, a) for (int i = 0; i < a; i++)
#define mp make_pair
#define P pair<int, int>
#define ll __int64
int n;
int x[4000], y[4000];
set<P> table;

int x1, x2, y1, y2, dx, dy, vx, vy;
bool isRect(P t1, P t2) {

  if (t1.first > t2.first)
    swap(t1, t2);

  x1 = t1.first;
  x2 = t2.first;
  y1 = t1.second;
  y2 = t2.second;

  dx = x2 - x1;
  dy = y2 - y1;
  vx = dy;
  vy = -dx;
  // cout<<x1<<" "<<y1<<" "<<x2<<" "<<y2<<" "<<dx<<" "<<dy<<endl;

  if (table.find(mp(x1 + vx, y1 + vy)) == table.end())
    return false;
  if (table.find(mp(x2 + vx, y2 + vy)) == table.end())
    return false;

  return true;
}

int main() {

  while (cin >> n, n) {

    table.clear();

    rep(i, 4000) x[i] = y[i] = 0;

    rep(i, n) {
      cin >> x[i] >> y[i];
      // table[mp(x[i],y[i])]=1;
      table.insert(mp(x[i], y[i]));
    }

    int ans = 0;

    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        if (isRect(mp(x[i], y[i]), mp(x[j], y[j]))) {

          ans = max(ans, ((x[i] - x[j]) * (x[i] - x[j])) +
                             ((y[i] - y[j]) * (y[i] - y[j])));
          // cout<<x[i]<<" "<<y[i]<<" "<<x[j]<<" "<<y[j]<<endl;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}


Error: MLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, a) for (int i = 0; i < a; i++)
#define mp make_pair
#define P pair<int, int>
#define ll __int64
int n;
int x[4000], y[4000];
map<P, bool> table;

int x1, x2, y1, y2, dx, dy, vx, vy;
bool isRect(P t1, P t2) {

  if (t1.first > t2.first)
    swap(t1, t2);

  x1 = t1.first;
  x2 = t2.first;
  y1 = t1.second;
  y2 = t2.second;

  dx = x2 - x1;
  dy = y2 - y1;
  vx = dy;
  vy = -dx;
  // cout<<x1<<" "<<y1<<" "<<x2<<" "<<y2<<" "<<dx<<" "<<dy<<endl;
  return (table[mp(x1 + vx, y1 + vy)] == true &&
          table[mp(x2 + vx, y2 + vy)] == true);
}

int main() {

  while (cin >> n, n) {

    table.clear();

    rep(i, 4000) x[i] = y[i] = 0;

    rep(i, n) {
      cin >> x[i] >> y[i];
      table[mp(x[i], y[i])] = 1;
    }

    int ans = 0;

    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        if (table.size() > 3000)
          cout << "WA";
        if (isRect(mp(x[i], y[i]), mp(x[j], y[j]))) {

          ans = max(ans, ((x[i] - x[j]) * (x[i] - x[j])) +
                             ((y[i] - y[j]) * (y[i] - y[j])));
          // cout<<x[i]<<" "<<y[i]<<" "<<x[j]<<" "<<y[j]<<endl;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00441 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;

int pole[3000][2];
int n;
int bin_search(int x, int y) {
  int h = 0;
  int t = n;
  int temp;
  while (h <= t) {
    temp = (t + h) / 2;
    if (x == pole[temp][0] && y == pole[temp][1]) {
      return true;
    } else if (x > pole[temp][0] || (x == pole[temp][0] && y > pole[temp][1]))
      t = temp - 1;
    else
      h = temp + 1;
  }
  return false;
}
int push(int x, int y, int limit) {
  int a = 0;
  while (a < limit && (x < pole[a][0] || (x == pole[a][0] && y < pole[a][1]))) {
    a++;
  }
  for (int i = limit; i > a; i--) {
    swap(pole[i][0], pole[i - 1][0]);
    swap(pole[i][1], pole[i - 1][1]);
  }
  pole[a][0] = x;
  pole[a][1] = y;
}
int main() {
  int temp[2];
  int dx, dy;
  int tx[2], ty[2];
  int m;
  cin >> n;
  while (n) {
    m = 0;
    for (int i = 0; i < n; i++) {
      cin >> temp[0] >> temp[1];
      push(temp[0], temp[1], i);
    }
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        dx = abs(pole[i][0] - pole[j][0]);
        dy = abs(pole[i][1] - pole[j][1]);
        if (bin_search(pole[i][0] + dy, pole[i][1] + dx) &&
            bin_search(pole[j][0] + dy, pole[j][1] + dx)) {
          m = max(dx * dx + dy * dy, m);
        }
      }
    }
    cout << m << endl;
    cin >> n;
  }
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;

int pole[3000][2];
int g[5000][5000];
int n;
int main() {
  int temp[2];
  int dx, dy;
  int tx[2], ty[2];
  int m;
  cin >> n;
  while (n) {
    m = 0;
    memset(g, 0, sizeof(g));
    for (int i = 0; i < n; i++) {
      cin >> temp[0] >> temp[1];
      temp[0]--;
      temp[1]--;
      g[temp[0]][temp[1]] = 1;
      pole[i][0] = temp[0];
      pole[i][1] = temp[1];
    }
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        dx = abs(pole[i][0] - pole[j][0]);
        dy = abs(pole[i][1] - pole[j][1]);
        if ((tx[0] = pole[i][0] + dy) < 5000 &&
            (ty[0] = pole[i][1] + dx) < 5000 &&
            (tx[1] = pole[j][0] + dy) < 5000 &&
            (ty[1] = pole[j][1] + dx) < 5000 && g[tx[0]][ty[0]] &&
            g[tx[1]][ty[1]]) {
          m = max(dx * dx + dy * dy, m);
        }
      }
    }
    cout << m << endl;
    cin >> n;
  }
}
Problem p00441 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <map>
#include <set>
using namespace std;
typedef pair<int, int> P;
int n;
P st[3000];
int main() {
  while (scanf("%d", &n)) {
    if (!n)
      break;
    set<P> stat;
    for (int i = 0; i < n; i++) {
      scanf("%d%d", &st[i].first, &st[i].second);
      stat.insert(st[i]);
    }
    int res = 0;
    for (int i = 0; i < n; i++) {
      P a = st[i];
      for (int j = 0; j < n; j++) {
        P b = st[j];
        int dist1 = b.first - a.first, dist2 = a.second - b.second;
        if (stat.find(P(b.first - dist2, b.second - dist1)) != stat.end() &&
            stat.find(P(a.first - dist2, a.second - dist1)) != stat.end()) {
          res = max(res, dist1 * dist1 + dist2 * dist2);
        }
      }
    }
    printf("%d\\n", res);
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <map>
#include <set>
using namespace std;
typedef pair<int, int> P;
int n;
P st[3000];
int main() {
  while (scanf("%d", &n)) {
    if (!n)
      break;
    set<P> stat;
    for (int i = 0; i < n; i++) {
      scanf("%d%d", &st[i].first, &st[i].second);
      stat.insert(st[i]);
    }
    int res = 0;
    for (int i = 0; i < n; i++) {
      P a = st[i];
      for (int j = 0; j < n; j++) {
        P b = st[j];
        int dist1 = b.first - a.first, dist2 = a.second - b.second;
        //                printf("%d %d %d %d:%d %d:%d %d %d
        //                %d\\n",a.first,a.second,b.first,b.second,dist1,dist2,a.first-dist2,a.second-dist1,b.first-dist2,b.second-dist1);
        int r1 = stat.count(P(b.first - dist2, b.second - dist1));
        int r2 = stat.count(P(a.first - dist2, a.second - dist1));
        //                printf("%d %d\\n",r1,r2);
        if (r1 && r2) {
          res = max(res, dist1 * dist1 + dist2 * dist2);
        }
      }
    }
    printf("%d\\n", res);
  }
}
Problem p00441 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <climits>
#include <cstring>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

#define x first
#define y second

int getArea(int x1, int y1, int x2, int y2, int x3, int y3) {
  return abs((x1 - x2) * (y3 - y2) - (x3 - x2) * (y1 - y2));
}

int main() {
  int n;
  while (cin >> n, n) {
    map<int, bool> has;

    vector<pair<int, int>> co(n);
    for (int i = 0; i < n; ++i) {
      cin >> co[i].x >> co[i].y;
      has[co[i].x + 10000 * co[i].y] = true;
    }
    sort(co.begin(), co.end());

    int area = 0;
    for (int i = 0; i < (int)co.size(); ++i) {
      for (int j = i + 1; j < (int)co.size(); ++j) {
        int dx, dy, x3, y3, x4, y4;
        dx = co[j].x - co[i].x;
        dy = co[j].y - co[i].y;
        x3 = co[j].x - dy;
        y3 = co[j].y + dx;
        x4 = co[i].x - dy;
        y4 = co[i].y + dx;
        if (has.count(x3 + 10000 * y3) && has.count(x4 + 10000 * y4)) {
          area = max(area, getArea(co[i].x, co[i].y, co[j].x, co[j].y, x3, y3));
        }
      }
    }
    cout << area << endl;
  }
  return 0;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <climits>
#include <cstring>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

#define x first
#define y second

int main() {
  int n;
  while (cin >> n, n) {
    map<int, bool> has;
    vector<pair<int, int>> co(n);
    for (int i = 0; i < n; ++i) {
      cin >> co[i].x >> co[i].y;
      has[co[i].x + 10000 * co[i].y] = true;
    }
    sort(co.begin(), co.end());

    int area = 0;
    for (int i = 0; i < (int)co.size(); ++i) {
      for (int j = i + 1; j < (int)co.size(); ++j) {
        int x1, y1, x2, y2, x3, y3, x4, y4, dx, dy;
        x1 = co[i].x;
        y1 = co[i].y;
        x2 = co[j].x;
        y2 = co[j].y;
        dx = x2 - x1;
        dy = y2 - y1;
        x3 = co[j].x - dy;
        y3 = co[j].y + dx;
        x4 = co[i].x - dy;
        y4 = co[i].y + dx;
        if (has[x3 + 10000 * y3] && has[x4 + 10000 * y4]) {
          area = max(area, abs((x1 - x2) * (y3 - y2) - (x3 - x2) * (y1 - y2)));
        }
      }
    }
    cout << area << endl;
  }
  return 0;
}