alexjercan/bugnet huggingface dataset:
Problem p00447 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ctype.h>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define REP(i, x, n) for (int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)

// 4方向ベクトル→↑←↓
int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};

int m; // 正座を構成するm個の星
int n; // 写真に写ってる全てのn個の星

typedef pair<int, int> P;

int main() {
  while (cin >> m, m) {
    int x, y;
    vector<P> seiza;
    vector<P> board;
    for (int i = 0; i < m; i++) {
      cin >> x >> y;
      seiza.push_back(P(x, y));
    }
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> x >> y;
      board.push_back(P(x, y));
    }
    map<P, int> Map;
    for (int i = 0; i < board.size(); i++) {
      for (int j = 0; j < seiza.size(); j++) {
        int dx = board[i].first - seiza[j].first;
        int dy = board[i].second - seiza[j].second;
        Map[P(dx, dy)]++;
      }
    }
    for (map<P, int>::iterator it = Map.begin(); it != Map.end(); it++) {
      if (it->second == seiza.size()) {
        x = it->first.first;
        y = it->first.second;
        break;
      }
    }
    cout << x << " " << y << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ctype.h>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define REP(i, x, n) for (int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)

// 4方向ベクトル→↑←↓
int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};

int m; // 正座を構成するm個の星
int n; // 写真に写ってる全てのn個の星

typedef pair<int, int> P;
vector<P> seiza;
vector<P> board;
int main() {
  while (cin >> m, m) {
    int x, y;
    seiza.clear();
    board.clear();
    for (int i = 0; i < m; i++) {
      cin >> x >> y;
      seiza.push_back(P(x, y));
    }
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> x >> y;
      board.push_back(P(x, y));
    }
    map<P, int> Map;
    for (int i = 0; i < board.size(); i++) {
      for (int j = 0; j < board.size(); j++) {
        int dx = board[i].first - seiza[j].first;
        int dy = board[i].second - seiza[j].second;
        Map[P(dx, dy)]++;
      }
    }
    for (map<P, int>::iterator it = Map.begin(); it != Map.end(); it++) {
      if (it->second == seiza.size()) {
        x = it->first.first;
        y = it->first.second;
        break;
      }
    }
    cout << x << " " << y << endl;
  }
  return 0;
}
Problem p00447 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
using namespace std;
typedef pair<int, int> PA;
int main() {
  int m, n;
  PA seiza[200], hosi[1001];
  while (scanf("%d", &m), m) {
    for (int i = 0; i < m; i++)
      scanf("%d %d", &seiza[i].first, &seiza[i].second);
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
      scanf("%d %d", &hosi[i].first, &hosi[i].second);
    sort(hosi, hosi + n);
    for (int i = 0; i < n; i++) {
      int x = hosi[i].first - seiza[0].first;
      int y = hosi[i].second - seiza[0].second;
      for (int j = 1; j < m; j++) {
        if (binary_search(hosi, hosi + n,
                          PA(seiza[j].first + x, seiza[j].second + y))) {
          if (j == m - 1)
            printf("%d %d\\n", x, y);
        } else
          break;
      }
    }
  }
  return (0);
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
using namespace std;
typedef pair<int, int> PA;
int main() {
  int m, n;
  PA seiza[200], hosi[200];
  while (scanf("%d", &m), m) {
    for (int i = 0; i < m; i++)
      scanf("%d %d", &seiza[i].first, &seiza[i].second);
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
      scanf("%d %d", &hosi[i].first, &hosi[i].second);
    sort(hosi, hosi + n);
    for (int i = 0; i < n; i++) {
      int x = hosi[i].first - seiza[0].first;
      int y = hosi[i].second - seiza[0].second;
      for (int j = 1; j < m; j++) {
        if (binary_search(hosi, hosi + n,
                          PA(seiza[j].first + x, seiza[j].second + y))) {
          if (j == m - 1)
            printf("%d %d\\n", x, y);
        } else
          break;
      }
    }
  }
  return (0);
}
Problem p00447 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>

#define sint(i) scanf("%d", &i)
#define sintt(i, j) scanf("%d%d", &i, &j)
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

int main() {
  int nx[200];
  int ny[200];
  int mx[1000];
  int my[1000];

  while (1) {
    int n;
    sint(n);

    if (n == 0) {
      break;
    }

    rep(i, n) { sintt(nx[i], ny[i]); }

    int m;
    sint(m);
    rep(i, m) { sintt(mx[i], my[i]); }

    rep(i, m) {
      rep(j, m) {
        int temp;
        if (mx[i] < mx[j]) {
          temp = mx[i];
          mx[i] = mx[j];
          mx[j] = temp;

          temp = my[i];
          my[i] = my[j];
          my[j] = temp;
        }
      }
    }

    rep(i, m) {
      int dx = mx[i] - nx[0];
      int dy = my[i] - ny[0];

      int flgg = 1;
      rep(j, n) {
        int flg = 0;
        rep(k, m) {
          if (nx[j] + dx == mx[k] && ny[j] + dy == my[k]) {
            flg = 1;
            break;
          }
        }

        if (flg == 0) {
          flgg = 0;
          break;
        }
      }

      if (flgg == 1) {
        printf("%d %d\\n", dx, dy);
        break;
      }
    }
  }
}

/*
5
8 5
6 4
4 3
7 10
0 10
10
10 5
2 7
9 7
8 10
10 2
1 2
8 1
6 7
6 0
0 9

2
1 1
2 2
3
1 2
2 3
1 1

*/

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>

#define sint(i) scanf("%d", &i)
#define sintt(i, j) scanf("%d%d", &i, &j)
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

int main() {
  int nx[200];
  int ny[200];
  int mx[200];
  int my[200];

  while (1) {
    int n;
    sint(n);

    if (n == 0) {
      break;
    }

    rep(i, n) { sintt(nx[i], ny[i]); }

    int m;
    sint(m);
    rep(i, m) { sintt(mx[i], my[i]); }

    rep(i, m) {
      rep(j, m) {
        int temp;
        if (mx[i] < mx[j]) {
          temp = mx[i];
          mx[i] = mx[j];
          mx[j] = temp;

          temp = my[i];
          my[i] = my[j];
          my[j] = temp;
        }
      }
    }

    rep(i, m) {
      int dx = mx[i] - nx[0];
      int dy = my[i] - ny[0];

      int flgg = 1;
      rep(j, n) {
        int flg = 0;
        rep(k, m) {
          if (nx[j] + dx == mx[k] && ny[j] + dy == my[k]) {
            flg = 1;
            break;
          }
        }

        if (flg == 0) {
          flgg = 0;
          break;
        }
      }

      if (flgg == 1) {
        printf("%d %d\\n", dx, dy);
        break;
      }
    }
  }
}

/*
5
8 5
6 4
4 3
7 10
0 10
10
10 5
2 7
9 7
8 10
10 2
1 2
8 1
6 7
6 0
0 9

2
1 1
2 2
3
1 2
2 3
1 1

*/
Problem p00447 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
struct cood {
  int x, y;
};
cood star[200], star2[1000];
int main() {
  int m, n;
  while (scanf("%d", &m)) {
    if (!m)
      break;
    for (int i = 0; i < m; i++) {
      int x, y;
      scanf("%d%d", &x, &y);
      star[i] = (cood){x, y};
    }
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
      int x, y;
      scanf("%d%d", &x, &y);
      star2[i] = (cood){x, y};
    }
    for (int i = 0; i < n; i++) {
      int j;
      int dx = star2[i].x - star[0].x;
      int dy = star2[i].y - star[0].y;
      for (j = 1; j < m; j++) {
        int x = star[j].x + dx;
        int y = star[j].y + dy;
        int k;
        for (k = 0; k < n; k++) {
          if (star2[k].x == x && star2[k].y == y)
            break;
        }
        if (k == n)
          break;
      }
      if (j == m) {
        printf("%d %d\\n", dx, dy);
        break;
      }
    }
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <map>
#include <vector>
using namespace std;
typedef pair<int, int> P;
struct cood {
  int x, y;
};
bool comp(const cood &a, const cood &b) { return a.x < b.x; }
cood star[200], star2[1000];
cood diff[1000][200];
int main() {
  int m, n;
  while (scanf("%d", &m) && m != 0) {
    for (int i = 0; i < m; i++)
      scanf("%d%d", &star[i].x, &star[i].y);
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
      int x, y;
      scanf("%d%d", &x, &y);
      star2[i] = (cood){x, y};
      for (int j = 0; j < m; j++) {
        diff[i][j] = (cood){x - star[j].x, y - star[j].y};
      }
    }
    sort(star2, star2 + n, comp);
    int dx = 0, dy = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        bool flag = true;
        for (int k = 0; k < m; k++) {
          if (k == j)
            continue;
          int x = star[k].x + diff[i][j].x, y = star[k].y + diff[i][j].y;
          flag = false;
          for (int l = 0; l < n; l++) {
            if (x == star2[l].x && y == star2[l].y) {
              flag = true;
              break;
            }
          }
          if (!flag)
            break;
        }
        if (flag) {
          dx = diff[i][j].x;
          dy = diff[i][j].y;
          break;
        }
      }
    }
    printf("%d %d\\n", dx, dy);
  }
}
Problem p00447 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  int i, j, k;
  int m, n;
  int constel[200][2];
  int constel_margin[199][2];
  int stars[1000][2];
  int temp[2];
  bool finish;
  cin >> m;
  while (m) {
    cin >> constel[0][0] >> constel[0][1];
    for (i = 1; i < m; i++) {
      cin >> constel[i][0] >> constel[i][1];
      constel_margin[i - 1][0] = constel[i][0] - constel[i - 1][0];
      constel_margin[i - 1][1] = constel[i][1] - constel[i - 1][1];
    }
    cin >> n;
    for (i = 0; i < n; i++) {
      cin >> stars[i][0] >> stars[i][1];
    }
    for (i = 0; i < n; i++) {
      k = 0;
      temp[0] = stars[i][0] + constel_margin[k][0];
      temp[1] = stars[i][1] + constel_margin[k][1];
      j = 0;
      finish = false;
      while (j < n) {
        if (stars[j][0] == temp[0] && stars[j][1] == temp[1]) {
          if (k == m - 2) {
            finish = true;
            break;
          }
          k++;
          temp[0] = stars[j][0] + constel_margin[k][0];
          temp[1] = stars[j][1] + constel_margin[k][1];
          j = 0;
        }
        j++;
      }
      if (finish) {
        break;
      }
    }
    cout << stars[i][0] - constel[0][0] << " ";
    cout << stars[i][1] - constel[0][1] << endl;
    cin >> m;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int i, j, k;
  int m, n;
  int constel[200][2];
  int constel_margin[199][2];
  int stars[1000][2];
  int margin[2];
  int temp[0];
  cin >> m;
  while (m) {
    cin >> constel[0][0] >> constel[0][1];
    for (i = 1; i < m; i++) {
      cin >> constel[i][0] >> constel[i][1];
      constel_margin[i - 1][0] = constel[i][0] - constel[i - 1][0];
      constel_margin[i - 1][1] = constel[i][1] - constel[i - 1][1];
    }
    cin >> n;
    for (i = 0; i < n; i++) {
      cin >> stars[i][0] >> stars[i][1];
    }
    for (i = 0; i < n; i++) {
      k = 0;
      temp[0] = stars[i][0] + constel_margin[k][0];
      temp[1] = stars[i][1] + constel_margin[k][1];
      for (j = 0; j < n; j++) {
        if (stars[j][0] == temp[0] && stars[j][1] == temp[1]) {
          if (k == m - 2) {
            break;
          }
          k++;
          temp[0] = stars[j][0] + constel_margin[k][0];
          temp[1] = stars[j][1] + constel_margin[k][1];
          j = 0;
        }
      }
      if (k == m - 2) {
        break;
      }
    }
    cout << stars[i][0] - constel[0][0] << " ";
    cout << stars[i][1] - constel[0][1] << endl;
    cin >> m;
  }
  return 0;
}
Problem p00447 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <map>

#define x first
#define y second

using namespace std;
typedef pair<int, int> P;
P hosi[220];
P hosi2[1010];
P shift;
bool flag;
int main() {
  int m, n;
  while (1) {
    cin >> m;
    if (!m)
      break;
    for (int i = 0; i < m; i++) {
      cin >> hosi[i].x >> hosi[i].y;
    }

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

    sort(hosi, hosi + m);
    sort(hosi2, hosi2 + n);

    for (int i = 0; i < n; i++) {
      flag = true;
      shift.x = hosi2[i].x - hosi[0].x;
      shift.y = hosi2[i].y - hosi[0].y;
      for (int j = 0; j < m; j++) {
        if (!binary_search(hosi2, hosi2 + n,
                           P(hosi[j].x + shift.x, hosi[j].y + shift.y))) {
          flag = false;
          break;
        }
      }
      if (flag == true)
        break;
    }
    cout << shift.x << " " << shift.y << endl;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>

#define x first
#define y second

using namespace std;
typedef pair<int, int> P;
P hosi[100];
P hosi2[100];
P shift;
bool flag;
int main() {
  int m, n;
  while (1) {
    cin >> m;
    if (!m)
      break;
    for (int i = 0; i < m; i++) {
      cin >> hosi[i].x >> hosi[i].y;
    }

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

    sort(hosi, hosi + m);
    sort(hosi2, hosi2 + n);

    for (int i = 0; i < n; i++) {
      flag = true;
      shift.x = hosi2[i].x - hosi[0].x;
      shift.y = hosi2[i].y - hosi[0].y;
      for (int j = 0; j < m; j++) {
        if (!binary_search(hosi2, hosi2 + n,
                           P(hosi[j].x + shift.x, hosi[j].y + shift.y))) {
          flag = false;
          break;
        }
      }
      if (flag == true)
        break;
    }
    cout << shift.x << " " << shift.y << endl;
  }
}
Problem p00447 (C++) — buggy submission, verdict: Runtime Error

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

typedef pair<int, int> P;
#define FOR(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rep(i, n) FOR(i, 0, n)
#define ZERO(a) memset(a, 0, sizeof(a))
#define pb push_back
#define mp make_pair
#define F first
#define S second

const int M = 1e6 + 10;
bool px[M], py[M];
vector<P> tg, stars; // (x,y)

void init(void) {
  ZERO(px);
  ZERO(py);
  tg.clear();
  stars.clear();
}

bool OK(int dx, int dy) {
  for (auto &t : tg) {
    if (t.F + dx > 1e6 or t.S + dy > 1e6)
      return false;
    if (!px[t.F + dx] or !py[t.S + dy])
      return false;
  }
  return true;
}

int main() {
  int m, n;
  while (cin >> m && m) {
    init();
    rep(i, m) {
      int x, y;
      scanf("%d%d", &x, &y);
      tg.pb(mp(x, y));
    }
    cin >> n;
    rep(i, n) {
      int x, y;
      scanf("%d%d", &x, &y);
      stars.pb(mp(x, y));
      px[x] = py[y] = true;
    }

    for (auto &star : stars) {
      int diffx = star.F - tg[0].F;
      int diffy = star.S - tg[0].S;

      if (OK(diffx, diffy)) {
        printf("%d %d\\n", diffx, diffy);
        goto out;
      }
    }
  out:
    m += 0;
  }

  return 0;
}

Error: 0

Fixed submission:

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

typedef pair<int, int> P;
#define FOR(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rep(i, n) FOR(i, 0, n)
#define ZERO(a) memset(a, 0, sizeof(a))
#define pb push_back
#define mp make_pair
#define F first
#define S second

const int M = 1e6 + 10;
bool px[M], py[M];
vector<P> tg, stars; // (x,y)

void init(void) {
  ZERO(px);
  ZERO(py);
  tg.clear();
  stars.clear();
}

bool OK(int dx, int dy) {
  for (auto &t : tg) {
    if (!px[t.F + dx] or !py[t.S + dy])
      return false;
  }
  return true;
}

int main() {
  int m, n;
  while (cin >> m && m) {
    init();
    rep(i, m) {
      int x, y;
      scanf("%d%d", &x, &y);
      tg.pb(mp(x, y));
    }
    cin >> n;
    rep(i, n) {
      int x, y;
      scanf("%d%d", &x, &y);
      stars.pb(mp(x, y));
      px[x] = py[y] = true;
    }

    for (auto &star : stars) {
      int diffx = star.F - tg[0].F;
      int diffy = star.S - tg[0].S;

      if (OK(diffx, diffy)) {
        printf("%d %d\\n", diffx, diffy);
        goto out;
      }
    }
  out:
    m += 0;
  }

  return 0;
}
Problem p00447 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
long long int seiza[201][2], point[1001][2], n, m, dx, dy;
int main() {
  for (;;) {
    cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> seiza[i][0] >> seiza[i][1];
    }
    cin >> m;
    for (int i = 0; i < m; i++) {
      cin >> point[i][0] >> point[i][1];
    }
    for (int i = 0; i < m; i++) {
      int j;
      dx = point[i][0] - seiza[0][0];
      dy = point[i][1] - seiza[0][1];
      for (j = 1; j < n; j++) {
        int x = seiza[j][0] + dx;
        int y = seiza[j][1] + dy;
        int k;
        for (k = 0; k < m; k++) {
          if (point[k][0] == x && point[k][1] == y)
            break;
        }
        if (k == m)
          break;
      }
      if (j == n) {
        cout << dx << " " << dy << endl;
        break;
      }
    }
  }
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int n, m, seizax[201], seizay[201], starx[201], stary[201], sax[201], say[201],
    ax, ay, z, cou;
bool ansx[1000001] = {false}, ansy[1000001] = {false};
int main() {
  for (;;) {
    cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> seizax[i] >> seizay[i];
    }
    for (int i = 1; i < n; i++) {
      sax[i - 1] = seizax[i] - seizax[0];
      say[i - 1] = seizay[i] - seizay[0];
    }
    cin >> m;
    for (int i = 0; i < m; i++) {
      cin >> starx[i] >> stary[i];
      ansx[starx[i]] = true;
      ansy[stary[i]] = true;
    }
    for (int i = 0; i < m; i++) {
      if (starx[i] + sax[0] >= 0 && starx[i] + sax[0] <= 1000000 &&
          stary[i] + say[0] >= 0 && stary[i] + say[0] <= 1000000) {
        if (ansx[starx[i] + sax[0]] && ansy[stary[i] + say[0]]) {
          for (int j = 1; j < n; j++) {
            if (starx[i] + sax[j] < 0 && starx[i] + sax[j] > 1000000 &&
                stary[i] + say[j] < 0 && stary[i] + say[j] > 1000000) {
              break;
            }
            if (ansx[starx[i] + sax[j]] == false ||
                ansy[stary[i] + say[j]] == false) {
              break;
            }
            if (cou == n - 2) {
              z = cou;
              ax = starx[i] - seizax[0];
              ay = stary[i] - seizay[0];
              break;
            }
            cou++;
          }
        }
      }
      if (z == n - 2)
        break;
    }
    cout << ax << " " << ay << endl;
  }
  return 0;
}
Problem p00447 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int seiza[200][2], star[1000][2], dx, dy, x, y, n, m, cou;
int main() {
  for (;;) {
    cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> seiza[i][0] >> seiza[i][1];
    }
    cin >> m;
    for (int i = 0; i < m; i++) {
      cin >> star[i][0] >> star[i][1];
    }
    for (int i = 0; i < m; i++) {
      cou = 0;
      dx = star[i][0] - seiza[0][0];
      dy = star[i][1] - seiza[0][1];
      for (int j = 1; j < n; j++) {
        x = seiza[j][0] + dx;
        y = seiza[j][1] + dy;
        for (int k = 0; k < m; k++) {
          if (star[k][0] == x && star[k][1] == y) {
            cou++;
            break;
          }
        }
        if (cou == n - 1)
          break;
      }
      if (cou == n - 1)
        break;
    }
    cout << dx << " " << dy << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int seiza[201][2], star[1000][2], n, m, dx, dy, x, y, a;
int main() {
  for (;;) {
    int seiza[201][2], star[1000][2], n, m, dx = 0, dy = 0, x, y, a = 0;
    cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> seiza[i][0] >> seiza[i][1];
    }
    cin >> m;
    for (int i = 0; i < m; i++) {
      cin >> star[i][0] >> star[i][1];
    }
    for (int i = 0; i < m; i++) {
      dx = star[i][0] - seiza[0][0];
      dy = star[i][1] - seiza[0][1];
      for (int j = 0; j < m; j++) {
        int c = 0;
        if (star[i][0] == seiza[0][0] + dx && star[i][1] == seiza[0][1] + dy) {
          for (int k = 1; k < n; k++) {
            for (int l = 0; l < m; l++) {
              if (star[l][0] == seiza[k][0] + dx &&
                  star[l][1] == seiza[k][1] + dy) {
                c++;
                break;
              }
            }
            if (c == n - 1)
              break;
          }
        }
        if (c == n - 1) {
          a = c;
          break;
        }
      }
      if (a == n - 1)
        break;
    }
    cout << dx << " " << dy << endl;
  }
}
Problem p00447 (C++) — buggy submission, verdict: Runtime Error


// aoj 0524 Searching Constellation

#include <iostream>

using namespace std;

int main() {
  while (1) {
    int n, m, roop = 1, a[200][2], b[1000][2], star[199][2];

    cin >> n;

    if (n == 0) {
      return 0;
    }

    for (int i = 0; i < n; i++) {

      cin >> a[i][0] >> a[i][1];
    }

    for (int i = 0; i < n - 1; i++) {

      star[i][0] = a[i + 1][0] - a[0][0];

      star[i][1] = a[i + 1][1] - a[0][1];
    }

    cin >> m;

    for (int i = 0; i < m; i++) {

      cin >> b[i][0] >> b[i][1];
    }

    for (int i = 0; i < m; i++) {

      for (int j = 0; j < n - 1; j++) {

        for (int k = 0; k < m; k++) {

          if (b[k][0] == (b[i][0] + star[j][0]) &&
              b[k][1] == (b[i][1] + star[j][1])) {

            roop++;

            if (n == roop) {

              cout << b[i][0] - a[0][0] << ' ' << b[i][1] - a[0][1] << endl;
            }

            break;
          }
        }
      }
      roop = 1;
    }
  }

  return 0;
}

Error: -11

Fixed submission:


// aoj 0524 Searching Constellation

#include <iostream>

using namespace std;

int starx[1000000] = {}, stary[1000000] = {}, starx2[1000000] = {},
    stary2[1000000] = {};

int main() {
  while (1) {
    int n, m, x, y, roop = 0, a[200][2], b[1000][2], star[10000000][2];

    cin >> n;

    if (n == 0) {
      return 0;
    }

    for (int i = 0; i < n; i++) {

      cin >> x >> y;

      starx[x] = 1;

      stary[y] = 1;

      a[i][0] = x;

      a[i][1] = y;
    }

    for (int i = 0; i < n - 1; i++) {

      star[i][0] = a[i + 1][0] - a[0][0];

      star[i][1] = a[i + 1][1] - a[0][1];
    }

    cin >> m;

    for (int i = 0; i < m; i++) {

      cin >> x >> y;

      starx2[x] = 1;

      stary2[y] = 1;

      b[i][0] = x;

      b[i][1] = y;
    }
    for (int i = 0; i < n; i++) {

      for (int j = 0; j < n; j++) {

        if (starx2[b[i][0] + star[j][0]] == 1 &&
            stary2[b[i][1] + star[j][1]] == 1) {

          roop++;

          if (n == roop) {

            cout << b[i][0] - a[0][0] << ' ' << b[i][1] - a[0][1] << endl;
          }

        } else {

          roop = 0;
        }
      }
    }
  }
  return 0;
}