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

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

int N;
int W, H;
double X1[222], Y1[222], X2[222], Y2[222];
int sx1[222], sy1[222];
int sx2[222], sy2[222];
bool F[555][555];
double dx[555], dy[555];

const double eps = 1e-10;

int search(const vector<double> &ps, double x) {
  for (int i = 0; i < ps.size(); i++)
    if (abs(ps[i] - x) < eps)
      return i;
  assert(false);
  return -1;
}

int zip(double *Z1, double *Z2, int *z1, int *z2, double *d) {
  vector<double> ps;
  for (int i = 0; i < N; i++) {
    ps.push_back(Z1[i]);
    ps.push_back(Z2[i]);
  }
  sort(ps.begin(), ps.end());
  ps.erase(unique(ps.begin(), ps.end()), ps.end());
  int w = ps.size();
  for (int i = 0; i < N; i++) {
    z1[i] = search(ps, Z1[i]);
    z2[i] = search(ps, Z2[i]);
  }
  for (int i = 0; i < w; i++) {
    d[i] = ps[i];
  }
  return w;
}

int main() {
  int ttt = 0;
  while (~scanf("%d", &N) && N) {
    memset(F, 0, sizeof(F));
    for (int i = 0; i < N; i++) {
      double x, y, r;
      scanf("%lf%lf%lf", &x, &y, &r);
      X1[i] = x - r;
      X2[i] = x + r;
      Y1[i] = y - r;
      Y2[i] = y + r;
    }
    W = zip(X1, X2, sx1, sx2, dx);
    H = zip(Y1, Y2, sy1, sy2, dy);
    for (int i = 0; i < N; i++) {
      // cout << sx1[i] << " - " <<sx2[i] << endl;
      // cout << sy1[i] << " - " <<sy2[i] << endl;
      for (int x = sx1[i]; x < sx2[i]; x++) {
        for (int y = sy1[i]; y < sy2[i]; y++) {
          F[x][y] = true;
        }
      }
    }
    double res = 0.0;
    for (int x = 0; x < W; x++) {
      for (int y = 0; y < H; y++) {
        if (F[x][y]) {
          // cout << dx[x+1]-dx[x] << " * " << dy[y+1]-dy[y] << endl;
          res += (dx[x + 1] - dx[x]) * (dy[y + 1] - dy[y]);
        }
      }
    }
    printf("%d %.2lf\\n", ++ttt, res);
  }
}

Error: 0

Fixed submission:

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

int N;
int W, H;
int X1[222], Y1[222], X2[222], Y2[222];
int sx1[222], sy1[222];
int sx2[222], sy2[222];
bool F[555][555];
int dx[555], dy[555];

int zip(int *Z1, int *Z2, int *z1, int *z2, int *d) {
  vector<int> ps;
  for (int i = 0; i < N; i++) {
    ps.push_back(Z1[i]);
    ps.push_back(Z2[i]);
  }
  sort(ps.begin(), ps.end());
  ps.erase(unique(ps.begin(), ps.end()), ps.end());
  int w = ps.size();
  for (int i = 0; i < w; i++) {
    z1[i] = lower_bound(ps.begin(), ps.end(), X1[i]) - ps.begin();
    z2[i] = lower_bound(ps.begin(), ps.end(), X2[i]) - ps.begin();
  }
  for (int i = 0; i < w; i++) {
    d[i] = ps[i];
  }
  return w;
}

int main() {
  int ttt = 0;
  while (~scanf("%d", &N) && N) {
    memset(F, 0, sizeof(F));
    for (int i = 0; i < N; i++) {
      int x, xx, y, yy, r, rr;
      scanf("%d.%d %d.%d %d.%d", &x, &xx, &y, &yy, &r, &rr);
      assert(xx < 10);
      assert(yy < 10);
      assert(rr < 10);
      x = x * 10 + xx;
      y = y * 10 + yy;
      r = r * 10 + rr;
      X1[i] = x - r;
      X2[i] = x + r;
      Y1[i] = y - r;
      Y2[i] = y + r;
    }
    W = zip(X1, X2, sx1, sx2, dx);
    H = zip(Y1, Y2, sy1, sy2, dy);
    for (int i = 0; i < N; i++) {
      // cout << sx1[i] << " - " <<sx2[i] << endl;
      // cout << sy1[i] << " - " <<sy2[i] << endl;
      for (int x = sx1[i]; x < sx2[i]; x++) {
        for (int y = sy1[i]; y < sy2[i]; y++) {
          F[x][y] = true;
        }
      }
    }
    long long res = 0.0;
    for (int x = 0; x < W; x++) {
      for (int y = 0; y < H; y++) {
        if (F[x][y]) {
          // cout << dx[x+1]-dx[x] << " * " << dy[y+1]-dy[y] << endl;
          res +=
              (long long)(dx[x + 1] - dx[x]) * (long long)(dy[y + 1] - dy[y]);
        }
      }
    }
    printf("%d %lld.%02lld\\n", ++ttt, res / 100LL, res % 100LL);
  }
}