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

#include <bits/stdc++.h>

using namespace std;

const int dx[] = {-1, 0, 0, 1};
const int dy[] = {0, -1, 1, 0};

int sx, sy, gx, gy, n, bx, by;
double P[3][3][20];

bool check(int x, int y) { return (0 <= x && x < 3 && 0 <= y && y < 3); }

void solve() {
  P[sy][sx][n] = 1;

  while (n) {
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        for (int k = 0; k < 4; k++) {
          int nx = i + dx[k];
          int ny = j + dy[k];
          if (!check(nx, ny) || (bx == nx && by == ny)) {
            P[j][i][n - 1] += P[j][i][n] / 4;
          } else if (check(nx, ny)) {
            P[ny][nx][n - 1] += P[j][i][n] / 4;
          }
        }
      }
    }
    n--;
  }

  printf("%.8f\\n", P[gy][gx][n]);
}

int main() {
  char s, t, b;

  while (cin >> n, n) {
    memset(P, 0, sizeof(P));

    cin >> s >> t >> b;
    int ss = s - 'A', tt = t - 'A', bb = b - 'A';
    sx = ss % 3;
    sy = ss / 3;
    gx = tt % 3;
    gy = tt / 3;
    bx = bb % 3;
    by = bb / 3;
    solve();
  }

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

const int dx[] = {-1, 0, 0, 1};
const int dy[] = {0, -1, 1, 0};

int sx, sy, gx, gy, n, bx, by;
double P[3][3][20];

bool check(int x, int y) { return (0 <= x && x < 3 && 0 <= y && y < 3); }

void solve() {
  P[sy][sx][n] = 1;

  queue<int> qx, qy, rem;
  qx.push(sx), qy.push(sy), rem.push(n);

  while (!qx.empty()) {
    int x = qx.front();
    qx.pop();
    int y = qy.front();
    qy.pop();
    int r = rem.front();
    rem.pop();

    if (r == 0)
      continue;

    for (int i = 0; i < 4; i++) {
      int nx = x + dx[i];
      int ny = y + dy[i];

      if (!check(nx, ny) || (nx == bx && ny == by)) {
        P[y][x][r - 1] += P[y][x][r] / 4;
        qx.push(x), qy.push(y), rem.push(r - 1);
      } else if (check(nx, ny)) {
        P[ny][nx][r - 1] += P[y][x][r] / 4;
        qx.push(nx), qy.push(ny), rem.push(r - 1);
      }
    }
  }

  printf("%.8f\\n", P[gy][gx][0]);
}

int main() {
  char s, t, b;

  while (cin >> n, n) {
    memset(P, 0, sizeof(P));

    cin >> s >> t >> b;
    int ss = s - 'A', tt = t - 'A', bb = b - 'A';
    sx = ss % 3;
    sy = ss / 3;
    gx = tt % 3;
    gy = tt / 3;
    bx = bb % 3;
    by = bb / 3;
    solve();
  }

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

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#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(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int INF = 100000000;

string m = "012345678";
P getP(char c) {
  int p = m[c - 'A'] - '0';
  return MP(p % 3, p / 3);
}

int dx[] = {0, 0, 1, -1};
int dy[] = {-1, 1, 0, 0};

int main() {
  while (1) {
    int n;
    char s, t, b;
    cin >> n;
    if (!n)
      break;
    cin >> s >> t >> b;

    P sp = getP(s);
    P tp = getP(t);
    P bp = getP(b);

    double p[16][3][3] = {};

    p[0][sp.Y][sp.X] = 1.0;

    for (int i = 1; i <= n; i++) {
      rep(j, 3) {
        rep(k, 3) {
          if (MP(k, j) == bp)
            continue;
          int wallcnt = 0;
          rep(l, 4) {
            int x = k + dx[l];
            int y = j + dy[l];
            if (x < 0 || x > 2 || y < 0 || y > 2 || MP(x, y) == bp) {
              wallcnt++;
              continue;
            }
            p[i][j][k] += p[i - 1][y][x] / 4;
          }
          p[i][j][k] += p[i - 1][j][k] * wallcnt / 4;
        }
      }
    }

    printf("%.8lf\\n", p[n][tp.Y][tp.X]);
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#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(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int INF = 100000000;

string m = "012345678";
P getP(char c) {
  int p = m[c - 'A'] - '0';
  return MP(p % 3, p / 3);
}

int dx[] = {0, 0, 1, -1};
int dy[] = {-1, 1, 0, 0};

int main() {
  while (1) {
    int n;
    char s, t, b;
    cin >> n;
    if (!n)
      break;
    cin >> s >> t >> b;

    P sp = getP(s);
    P tp = getP(t);
    P bp = getP(b);

    double p[15][3][3] = {};

    p[0][sp.Y][sp.X] = 1.0;

    for (int i = 1; i <= n; i++) {
      rep(j, 3) {
        rep(k, 3) {
          if (MP(k, j) == bp)
            continue;
          int wallcnt = 0;
          rep(l, 4) {
            int x = k + dx[l];
            int y = j + dy[l];
            if (x < 0 || x > 2 || y < 0 || y > 2 || MP(x, y) == bp) {
              wallcnt++;
              continue;
            }
            p[i][j][k] += p[i - 1][y][x] / 4;
          }
          p[i][j][k] += p[i - 1][j][k] * wallcnt / 4;
        }
      }
    }

    printf("%.8lf\\n", p[n][tp.Y][tp.X]);
  }

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

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#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(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second
#define debug(x) cout << #x << " = " << x << endl;

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;

const int FIELD_SIZE = 10000;

int main() {
  int an, bn, r;
  while (cin >> an >> bn >> r, an | bn) {
    vector<vi> ay(FIELD_SIZE);
    rep(i, an) {
      int x, y;
      cin >> x >> y;
      ay[x].push_back(y);
    }

    rep(i, FIELD_SIZE) sort(all(ay[i]));

    int R = 4 * r;
    int RR = 16 * r * r;
    int ans = 0;
    rep(i, bn) {
      int bx, by;
      cin >> bx >> by;

      for (int dx = -R; dx <= R; dx++) {
        int nx = bx + dx;
        if (nx < 0)
          dx = -bx, nx = 0;
        if (nx > FIELD_SIZE)
          break;
        int dy = sqrt((double)RR - dx * dx);
        ans += upper_bound(all(ay[nx]), by + dy) -
               lower_bound(all(ay[nx]), by - dy);
      }
    }
    cout << ans << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#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(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second
#define debug(x) cout << #x << " = " << x << endl;

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;

const int FIELD_SIZE = 10000;

int main() {
  int an, bn, r;
  while (cin >> an >> bn >> r, an | bn) {
    vector<P> a(an);
    rep(i, an) {
      int x, y;
      cin >> x >> y;
      a[i] = MP(x, y);
    }

    sort(all(a));

    int R = 4 * r;
    int RR = 16 * r * r;
    int ans = 0;
    rep(i, bn) {
      int bx, by;
      cin >> bx >> by;
      for (int dx = -R; dx <= R; dx++) {
        int nx = bx + dx;
        if (nx < 0)
          dx = -bx, nx = 0;
        if (nx > FIELD_SIZE)
          break;
        int dy = sqrt((double)RR - dx * dx);
        ans += upper_bound(all(a), MP(nx, by + dy)) -
               lower_bound(all(a), MP(nx, by - dy));
      }
    }
    cout << ans << endl;
  }

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

#include <cstdio>
#include <vector>

using namespace std;

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

int main() {
  while (true) {
    int an, bn, r;
    scanf("%d %d %d", &an, &bn, &r);
    if (an == 0)
      break;
    int a[an];
    rep(i, an) {
      int x, y;
      scanf("%d %d", &x, &y);
      a[i] = (x + 50) * 10112 + y + 50;
    }
    vector<bool> b(10112 * 10112, false);
    rep(i, bn) {
      int x, y;
      scanf("%d %d", &x, &y);
      b[(x + 50) * 10112 + y + 50] = true;
    }
    int res = 0;
    int d[10000];
    int t = 0;
    for (int i = -4 * r; i <= 4 * r; ++i)
      for (int j = -4 * r; j <= 4 * r; ++j)
        if (4 * r * r <= i * i + j * j && i * i + j * j <= 16 * r * r)
          d[t++] = i * 10112 + j;
    rep(i, an) rep(j, t) if (b[a[i] + d[j]])++ res;
    printf("%d\\n", res);
  }
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <vector>

using namespace std;

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

int main() {
  while (true) {
    int an, bn, r;
    scanf("%d %d %d", &an, &bn, &r);
    if (an == 0)
      break;
    int a[an];
    rep(i, an) {
      int x, y;
      scanf("%d %d", &x, &y);
      a[i] = (x + 50) * 10112 + y + 50;
    }
    vector<bool> b(10112 * 10112, false);
    rep(i, bn) {
      int x, y;
      scanf("%d %d", &x, &y);
      b[(x + 50) * 10112 + y + 50] = true;
    }
    int res = 0;
    vector<int> d;
    for (int i = -4 * r; i <= 4 * r; ++i)
      for (int j = -4 * r; j <= 4 * r; ++j)
        if (4 * r * r <= i * i + j * j && i * i + j * j <= 16 * r * r)
          d.push_back(i * 10112 + j);
    rep(i, an) rep(j, d.size()) if (b[a[i] + d[j]])++ res;
    printf("%d\\n", res);
  }
}
Problem p00609 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define MAX 10005
set<int> G[MAX];
int n, m, x, y, R;
int main() {
  while (1) {
    scanf("%d %d %d", &n, &m, &R);
    if (n == 0 && m == 0)
      break;
    for (int i = 0; i < MAX; i++)
      G[i].clear();

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

    int ans = 0;
    while (m--) {
      scanf("%d %d", &x, &y);
      set<int>::iterator it, it2;
      for (int px = x - R * 4; px <= x + R * 4; px++) {
        if (px < 0 || MAX <= px)
          continue;

        int py = y - R * 4;
        it = G[px].lower_bound(py);
        it2 = G[px].end();
        while (it != it2 && (*it) <= y + R * 4) {
          int X = px - x;
          int Y = (*it) - y;
          if (16 * R * R >= X * X + Y * Y) {
            ans++;
          }
          it++;
        }
      }
    }
    printf("%d\\n", ans);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define MAX 10005
set<int> G[MAX];
int n, m, x, y, R;
int main() {
  while (1) {
    scanf("%d %d %d", &n, &m, &R);
    if (n == 0 && m == 0)
      break;
    for (int i = 0; i < MAX; i++)
      G[i].clear();

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

    int ans = 0;
    while (m--) {
      scanf("%d %d", &x, &y);
      set<int>::iterator it, it2;
      for (int px = x - R * 4; px <= x + R * 4; px++) {
        int py = y - R * 4;
        it = G[px].lower_bound(py);
        it2 = G[px].end();
        while (it != it2 && (*it) <= y + R * 4) {
          int X = px - x;
          int Y = (*it) - y;
          if (16 * R * R >= X * X + Y * Y) {
            ans++;
          }
          it++;
        }
      }
    }
    printf("%d\\n", ans);
  }
  return 0;
}
Problem p00609 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>
#define MAX 110000
using namespace std;

vector<int> ay[MAX];
int an, bn, x, y, r;

int D(int t) {
  int ret = 0;
  while (ret * ret <= r * r - t * t)
    ret++;
  return ret - 1;
}

int main() {

  while (cin >> an >> bn >> r && an + bn) {
    for (int i = 0; i < MAX; i++) {
      ay[i].clear();
    }
    r *= 4;
    for (int i = 0; i < an; i++) {
      cin >> x >> y;
      ay[x].push_back(y);
    }
    for (int i = 0; i < an; i++) {
      sort(ay[i].begin(), ay[i].end());
    }
    int ans = 0;
    while (bn--) {
      cin >> x >> y;
      for (int i = max(0, x - r); i <= min(MAX - 100, x + r);
           i++) { //??¢?´¢??????????±????x??§?¨?
        ans += lower_bound(ay[i].begin(), ay[i].end(), y + D(x - i) + 1) -
               lower_bound(ay[i].begin(), ay[i].end(), y - D(x - i));
      } //                 ???
        //                 x??§?¨???????y??§?¨??????????????????¢?´¢??????y??§?¨??????????
    }
    cout << ans << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
#define MAX 11000
using namespace std;

vector<int> ay[MAX];
int an, bn, x, y, r;

int D(int t) {
  int ret = 0;
  while (ret * ret < r * r - t * t)
    ret++;
  return ret - 1;
}

int main() {
  while (cin >> an >> bn >> r && an + bn) {
    for (int i = 0; i < MAX; i++) {
      ay[i].clear();
    }
    r *= 4;
    for (int i = 0; i < an; i++) {
      cin >> x >> y;
      ay[x].push_back(y);
    }
    for (int i = 0; i < an; i++) {
      sort(ay[i].begin(), ay[i].end());
    }
    int ans = 0;
    while (bn--) {
      cin >> x >> y;
      for (int i = max(0, x - r); i <= min(MAX - 100, x + r); i++) {
        ans += lower_bound(ay[i].begin(), ay[i].end(), x + D(y - i)) -
               lower_bound(ay[i].begin(), ay[i].end(), x - D(y - i));
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00609 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

int AN, BN, R, XA, YA, XB, YB;

inline long long makeKey(int x, int y) { return x * 10000 + y; }

inline int getX(long long key) { return key / 10000; }

inline int getY(long long key) { return key % 10000; }

int main() {
  ios::sync_with_stdio(false);
  while (1) {
    cin >> AN >> BN >> R;
    if (!AN && !BN && !R)
      break;

    vector<long long> xy;
    for (int i = 0; i < AN; ++i) {
      cin >> XA >> YA;
      xy.push_back(makeKey(XA, YA));
    }
    sort(begin(xy), end(xy));

    int ans = 0;
    for (int i = 0; i < BN; ++i) {
      cin >> XB >> YB;
      auto begin_it = lower_bound(begin(xy), end(xy), makeKey(XB - 4 * R, 0));
      auto end_it = lower_bound(begin(xy), end(xy), makeKey(XB + 4 * R + 1, 0));
      for (auto it = begin_it; it != end_it; ++it) {
        int dx = getX(*it) - XB;
        int dy = getY(*it) - YB;
        ans += (dx * dx + dy * dy <= 16 * R * R);
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: MLE

Fixed submission:

#include <iostream>
#include <unordered_map>
using namespace std;

int AN, BN, R, XA, YA, XB, YB;
unordered_map<long long, bool> exist;

long long makeKey(int x, int y) { return x * 100000 + y; }

int main() {
  ios::sync_with_stdio(false);
  while (1) {
    cin >> AN >> BN >> R;
    if (!AN && !BN && !R) {
      break;
    }
    for (int i = 0; i < AN; ++i) {
      cin >> XA >> YA;
      exist[makeKey(XA, YA)] = true;
    }
    int ans = 0;
    for (int i = 0; i < BN; ++i) {
      cin >> XB >> YB;
      for (int x = XB - 2 * R; x <= XB + 2 * R; ++x) {
        for (int y = YB - 2 * R; y <= YB + 2 * R; ++y) {
          if ((x - XB) * (x - XB) + (y - YB) * (y - YB) <= (4 * R) * (4 * R)) {
            ans += exist[makeKey(x, y)];
          }
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00609 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

int distance(int x1, int y1, int x2, int y2) {
  int x = x1 - x2, y = y1 - y2;
  return x * x + y * y;
}
int main() {
  int an, bn, r;
  while (scanf("%d%d", &an, &bn), an | bn) {
    scanf("%d", &r);

    const int MAX = 100100;
    static pair<int, int> a[MAX], b[MAX];

    const int dis = 4 * r;
    const int sq_dis = dis * dis;
    for (int i = 0; i < an; ++i)
      scanf("%d%d", &a[i].first, &a[i].second);
    for (int i = 0; i < bn; ++i)
      scanf("%d%d", &b[i].first, &b[i].second);

    sort(a, a + an);
    sort(b, b + bn);

    int res = 0;
    for (int i = 0; i < an; ++i) {
      int x = a[i].first, y = a[i].second;
      int t = lower_bound(b, b + bn, make_pair(x - dis, 0)) - b;
      int sum = 0;
      for (int j = t; j < bn && b[j].first - x <= dis; ++j) {
        if (distance(x, y, b[j].first, b[j].second) <= sq_dis)
          ++sum;
      }
      res += sum;
    }
    printf("%d\\n", res);
  }
}

Error: TLE

Fixed submission:

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

using namespace std;

double distance(int x1, int y1, int x2, int y2) {
  int x = x1 - x2, y = y1 - y2;
  return sqrt(x * x + y * y);
}
int main() {
  int an, bn, r;
  while (scanf("%d%d", &an, &bn), an | bn) {
    scanf("%d", &r);

    const int MAX = 100100;
    static pair<int, int> a[MAX], b[MAX];

    const int dis = 4 * r;
    for (int i = 0; i < an; ++i)
      scanf("%d%d", &a[i].first, &a[i].second);
    for (int i = 0; i < bn; ++i)
      scanf("%d%d", &b[i].first, &b[i].second);

    sort(a, a + an);
    sort(b, b + bn);

    int res = 0;
    for (int i = 0; i < an; ++i) {
      int x = a[i].first, y = a[i].second;
      int t = lower_bound(b, b + bn, make_pair(x - dis, 0)) - b;
      int sum = 0;
      for (int j = t; j < bn && b[j].first - x <= dis; ++j) {
        if (distance(x, y, b[j].first, b[j].second) < dis + 1e-6)
          ++sum;
      }
      res += sum;
    }
    printf("%d\\n", res);
  }
}
Problem p00609 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef istringstream ISS;
typedef ostringstream OSS;
typedef vector<string> VS;
typedef int INT;
typedef vector<INT> VI;
typedef vector<VI> VVI;
typedef pair<INT, INT> II;
typedef vector<II> VII;

template <class T> ostream &operator<<(ostream &os, vector<T> v) {
  for (typename vector<T>::iterator it_i = v.begin(); it_i != v.end(); ++it_i) {
    os << *it_i << ", ";
  }
  return os;
}

typedef pair<int, int> PII;
typedef vector<PII> VP;

const int SIZE = 100001;
const int Y_SIZE = 10000;
int a, b, r;
VI A[Y_SIZE];
int X[SIZE], Y[SIZE];

double sq(double x) { return x * x; }

bool input() {
  if (!(cin >> a >> b >> r && a))
    return false;
  for (int i = 0; i < Y_SIZE; ++i) {
    A[i].clear();
  }
  for (int i = 0; i < a; ++i) {
    int x, y;
    cin >> x >> y;
    A[y].push_back(x);
  }
  for (int i = 0; i < Y_SIZE; ++i) {
    sort(A[i].begin(), A[i].end());
  }
  for (int i = 0; i < b; ++i) {
    cin >> X[i] >> Y[i];
  }
  return true;
}

int solve() {
  int res = 0;
  for (int i = 0; i < b; ++i) {
    int x = X[i], y = Y[i];
    for (int j = y - 4 * r; j <= y + 4 * r; ++j) {
      if (j < 0 || j >= Y_SIZE)
        continue;
      if (A[j].empty())
        continue;
      int range = (int)sqrt(sq(4.0 * r) - sq(y - j));
      res += upper_bound(A[j].begin(), A[j].end(), x + range) -
             lower_bound(A[j].begin(), A[j].end(), x - range);
    }
  }
  return res;
}

int main() {
  while (input()) {
    cout << solve() << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef pair<int, int> PII;
typedef vector<PII> VP;

int r;

bool check(double d) { return d < 4 * r || fabs(d - 4 * r) < 1e-9; }

double get_distance(int x1, int y1, int x2, int y2) {
  double x = x2 - x1;
  double y = y2 - y1;
  return sqrt(x * x + y * y);
}

bool check(PII a, PII b) {
  double d = get_distance(a.first, a.second, b.first, b.second);
  return check(d);
}

int main() {
  int a, b;
  while (cin >> a >> b >> r) {
    if (a == 0 && b == 0)
      break;
    VP A(a);
    VP B(b);
    for (int i = 0; i < a; ++i) {
      cin >> A[i].first >> A[i].second;
    }
    for (int i = 0; i < b; ++i) {
      cin >> B[i].first >> B[i].second;
    }
    int answer = 0;
    for (int i = 0; i < a; ++i) {
      for (int j = 0; j < b; ++j) {
        if (check(A[i], B[j])) {
          answer++;
        }
      }
    }
    cout << answer << endl;
  }
  return 0;
}
Problem p00609 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(), (c).end())

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

using namespace std;
int main(void) {
  for (;;) {
    int a, b, r;
    cin >> a >> b >> r;
    if (!a && !b)
      return 0;
    int range[64] = {};
    REP(i, r * 4 + 1)
    REP(j, r * 4 + 1) if (i * i + j * j <= 16 * r * r) range[i]++;
    vector<vector<int>> figx;
    figx.assign(10000, vector<int>());
    REP(i, a) {
      int xa, ya;
      scanf("%d%d", &xa, &ya);
      figx[xa].push_back(ya);
    }
    REP(i, 10000) SORT(figx[i]);
    int answer = 0;
    REP(bul, b) {
      int xb, yb;
      scanf("%d%d", &xb, &yb);
      FOR(dx, max(-r * 4, -xb), min(r * 4 + 1, 10000 - xb)) {
        int sec = range[abs(dx)];
        int nx = xb + dx;
        if (sec)
          answer +=
              upper_bound(figx[nx].begin(), figx[nx].end(), yb + sec - 1) -
              lower_bound(figx[nx].begin(), figx[nx].end(), yb - sec + 1);
      }
    }
    cout << answer << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(), (c).end())

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

using namespace std;
int main(void) {
  for (;;) {
    int a, b, r;
    cin >> a >> b >> r;
    if (!a && !b)
      return 0;
    int range[64] = {};
    REP(i, r * 4 + 1)
    REP(j, r * 4 + 1) if (i * i + j * j <= 16 * r * r) range[i]++;
    vector<pair<int, int>> fig;
    REP(i, a) {
      int xa, ya;
      scanf("%d%d", &xa, &ya);
      fig.push_back(make_pair(xa, ya));
    }
    SORT(fig);
    int answer = 0;
    REP(bul, b) {
      int xb, yb;
      scanf("%d%d", &xb, &yb);
      FOR(dx, -r * 4, r * 4 + 1) {
        int sec = range[abs(dx)];
        if (sec)
          answer += upper_bound(fig.begin(), fig.end(),
                                make_pair(xb + dx, yb + sec - 1)) -
                    lower_bound(fig.begin(), fig.end(),
                                make_pair(xb + dx, yb - sec + 1));
      }
    }
    cout << answer << endl;
  }
}