Problem p03004 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

#define MAX 1e8

class V {
public:
  vector<double> l;
  vector<double> r;

  V() {
    l = vector<double>(3, MAX);
    r = vector<double>(3, -MAX);
  }
  void add(double x, int d) {
    d++;
    l[d] = min(l[d], x);
    r[d] = max(r[d], x);
  }
  vector<double> intersection() {
    vector<double> ret;
    ret.push_back(l[0] - l[1]);
    ret.push_back(l[1] - l[2]);
    ret.push_back((l[0] - l[2]) / 2);

    ret.push_back(r[0] - r[1]);
    ret.push_back(r[1] - r[2]);
    ret.push_back((r[0] - r[2]) / 2);
    return ret;
  }

  double value(double t) {
    return max({r[0] - t, r[1], r[2] + t}) - min({l[0] - t, l[1], l[2] + t});
  }
};

void add_candidate(vector<double> x, vector<double> &candidate) {
  candidate.push_back(x[0] - x[1]);
  candidate.push_back(x[1] - x[2]);
  candidate.push_back((x[0] - x[2]) / 2);
}

int main() {
  int N;
  cin >> N;

  // [minus, const, plus]
  V X;
  V Y;
  vector<double> xmin(3, MAX);
  vector<double> xmax(3, -MAX);
  vector<double> ymin(3, MAX);
  vector<double> ymax(3, -MAX);
  double x, y;
  char D;
  for (int i = 0; i < N; i++) {
    cin >> x >> y;
    cin >> D;

    switch (D) {
    case 'R':
      X.add(x, 1);
      Y.add(y, 0);
      break;
    case 'L':
      X.add(x, -1);
      Y.add(y, 0);
      break;
    case 'U':
      X.add(x, 0);
      Y.add(y, 1);
      break;
    case 'D':
      X.add(x, 0);
      Y.add(y, -1);
      break;
    default:
      break;
    }
    if (D == 'L') {
      xmin[0] = min(xmin[0], x);
      xmax[0] = max(xmax[0], x);
    } else if (D == 'R') {
      xmin[2] = min(xmin[2], x);
      xmax[2] = max(xmax[2], x);
    } else {
      xmin[1] = min(xmin[1], x);
      xmax[1] = max(xmax[1], x);
    }

    if (D == 'D') {
      ymin[0] = min(ymin[0], y);
      ymax[0] = max(ymax[0], y);
    } else if (D == 'U') {
      ymin[2] = min(xmin[2], y);
      ymax[2] = max(xmax[2], y);
    } else {
      ymin[1] = min(ymin[1], y);
      ymax[1] = max(ymax[1], y);
    }
  }

  vector<double> candidate1;
  for (auto c : X.intersection()) {
    if (c >= 0) {
      candidate1.push_back(c);
    }
  }
  for (auto c : Y.intersection()) {
    if (c >= 0) {
      candidate1.push_back(c);
    }
  }
  candidate1.push_back(0);

  vector<double> candidate2;
  add_candidate(xmin, candidate2);
  add_candidate(xmax, candidate2);
  add_candidate(ymin, candidate2);
  add_candidate(ymax, candidate2);
  candidate2.push_back(0);

  double ans1 = 1e18;
  for (double c : candidate1) {
    if (c >= 0) {
      // x = X.value(c);
      // y = Y.value(c);
      x = max({X.r[0] - c, X.r[1], X.r[2] + c}) -
          min({X.l[0] - c, X.l[1], X.l[2] + c});
      y = max({Y.r[0] - c, Y.r[1], Y.r[2] + c}) -
          min({Y.l[0] - c, Y.l[1], Y.l[2] + c});

      ans1 = min(ans1, x * y);
    }
  }
  double ans2 = 1e18;
  for (double c : candidate2) {
    if (c >= 0) {
      x = max({xmax[0] - c, xmax[1], xmax[2] + c}) -
          min({xmin[0] - c, xmin[1], xmin[2] + c});
      y = max({ymax[0] - c, ymax[1], ymax[2] + c}) -
          min({ymin[0] - c, ymin[1], ymin[2] + c});
      ans2 = min(ans2, x * y);
    }
  }

  cout << fixed << setprecision(2) << ans1 << endl;

  assert(ans1 == ans2);
}


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

#define MAX 1e8

class V {
public:
  vector<double> l;
  vector<double> r;

  V() {
    l = vector<double>(3, MAX);
    r = vector<double>(3, -MAX);
  }
  void add(double x, int d) {
    d++;
    l[d] = min(l[d], x);
    r[d] = max(r[d], x);
  }
  vector<double> intersection() {
    vector<double> ret;
    ret.push_back(l[0] - l[1]);
    ret.push_back(l[1] - l[2]);
    ret.push_back((l[0] - l[2]) / 2);

    ret.push_back(r[0] - r[1]);
    ret.push_back(r[1] - r[2]);
    ret.push_back((r[0] - r[2]) / 2);
    return ret;
  }

  double value(double t) {
    return max({r[0] - t, r[1], r[2] + t}) - min({l[0] - t, l[1], l[2] + t});
  }
};

void add_candidate(vector<double> x, vector<double> &candidate) {
  candidate.push_back(x[0] - x[1]);
  candidate.push_back(x[1] - x[2]);
  candidate.push_back((x[0] - x[2]) / 2);
}

int main() {
  int N;
  cin >> N;

  // [minus, const, plus]
  V X;
  V Y;
  vector<double> xmin(3, MAX);
  vector<double> xmax(3, -MAX);
  vector<double> ymin(3, MAX);
  vector<double> ymax(3, -MAX);
  double x, y;
  char D;
  for (int i = 0; i < N; i++) {
    cin >> x >> y;
    cin >> D;

    switch (D) {
    case 'R':
      X.add(x, 1);
      Y.add(y, 0);
      break;
    case 'L':
      X.add(x, -1);
      Y.add(y, 0);
      break;
    case 'U':
      X.add(x, 0);
      Y.add(y, 1);
      break;
    case 'D':
      X.add(x, 0);
      Y.add(y, -1);
      break;
    default:
      break;
    }
    if (D == 'L') {
      xmin[0] = min(xmin[0], x);
      xmax[0] = max(xmax[0], x);
    } else if (D == 'R') {
      xmin[2] = min(xmin[2], x);
      xmax[2] = max(xmax[2], x);
    } else {
      xmin[1] = min(xmin[1], x);
      xmax[1] = max(xmax[1], x);
    }

    if (D == 'D') {
      ymin[0] = min(ymin[0], y);
      ymax[0] = max(ymax[0], y);
    } else if (D == 'U') {
      ymin[2] = min(xmin[2], y);
      ymax[2] = max(xmax[2], y);
    } else {
      ymin[1] = min(ymin[1], y);
      ymax[1] = max(ymax[1], y);
    }
  }

  vector<double> candidate1;
  for (auto c : X.intersection()) {
    if (c >= 0) {
      candidate1.push_back(c);
    }
  }
  for (auto c : Y.intersection()) {
    if (c >= 0) {
      candidate1.push_back(c);
    }
  }
  candidate1.push_back(0);

  vector<double> candidate2;
  add_candidate(xmin, candidate2);
  add_candidate(xmax, candidate2);
  add_candidate(ymin, candidate2);
  add_candidate(ymax, candidate2);
  candidate2.push_back(0);

  double ans1 = 1e18;
  for (double c : candidate1) {
    if (c >= 0) {
      // x = X.value(c);
      // y = Y.value(c);
      x = max({X.r[0] - c, X.r[1], X.r[2] + c}) -
          min({X.l[0] - c, X.l[1], X.l[2] + c});
      y = max({Y.r[0] - c, Y.r[1], Y.r[2] + c}) -
          min({Y.l[0] - c, Y.l[1], Y.l[2] + c});

      ans1 = min(ans1, x * y);
    }
  }
  double ans2 = 1e18;
  for (double c : candidate2) {
    if (c >= 0) {
      x = max({xmax[0] - c, xmax[1], xmax[2] + c}) -
          min({xmin[0] - c, xmin[1], xmin[2] + c});
      y = max({ymax[0] - c, ymax[1], ymax[2] + c}) -
          min({ymin[0] - c, ymin[1], ymin[2] + c});
      ans2 = min(ans2, x * y);
    }
  }

  cout << fixed << setprecision(2) << ans1 << endl;

  // assert(ans1 == ans2);
}