Problem p03004 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type>
#define endl '\n'

#define FOR(i, A, B) for (auto i = (A); i != (B); i++)
#define FORD(i, A, B) for (auto i = (A); i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
};

int main(int argc, char **argv) {
  io_init();

  // Actual program code starts here.
  int N;
  cin >> N;
  VEC(char) Directions(N);
  VEC(int) X(N), Y(N);
  FOR(i, 0, N) { cin >> X[i] >> Y[i] >> Directions[i]; }

  auto area = [&N, &X, &Y, &Directions](double t) {
    double xlo = 1e10, xhi = -(1e10);
    double ylo = 1e10, yhi = -(1e10);
    FOR(i, 0, N) {
      double x = X[i], y = Y[i];
      if (Directions[i] == 'U')
        y += t;
      else if (Directions[i] == 'D')
        y -= t;
      else if (Directions[i] == 'R')
        x += t;
      else
        x -= t;

      xlo = min(xlo, x);
      ylo = min(ylo, y);
      xhi = max(xhi, x);
      yhi = max(yhi, y);
    }

    return (xhi - xlo) * (yhi - ylo);
  };

  double lo = 0, hi = 1e10;

  while (hi - lo > 1e-10) {
    double md1 = (2 * lo + hi) / 3, md2 = (lo + 2 * hi) / 3;
    if (area(md1) < area(md2))
      hi = md2;
    else
      lo = md1;
  }

  cout << fixed << setprecision(10) << area((lo + hi) / 2) << endl;
  return 0;
};


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type>
#define endl '\n'

#define FOR(i, A, B) for (auto i = (A); i != (B); i++)
#define FORD(i, A, B) for (auto i = (A); i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
};

int main(int argc, char **argv) {
  io_init();

  // Actual program code starts here.
  int N;
  cin >> N;
  VEC(char) Directions(N);
  VEC(int) X(N), Y(N);
  FOR(i, 0, N) { cin >> X[i] >> Y[i] >> Directions[i]; }

  auto area = [&N, &X, &Y, &Directions](double t) {
    double xlo = 1e10, xhi = -(1e10);
    double ylo = 1e10, yhi = -(1e10);
    FOR(i, 0, N) {
      double x = X[i], y = Y[i];
      if (Directions[i] == 'U')
        y += t;
      else if (Directions[i] == 'D')
        y -= t;
      else if (Directions[i] == 'R')
        x += t;
      else
        x -= t;

      xlo = min(xlo, x);
      ylo = min(ylo, y);
      xhi = max(xhi, x);
      yhi = max(yhi, y);
    }

    return (xhi - xlo) * (yhi - ylo);
  };

  double lo = 0, hi = 1e10;

  int iters = 150;
  while (iters-- && hi - lo > 1e-10) {
    double md1 = (2 * lo + hi) / 3, md2 = (lo + 2 * hi) / 3;
    if (area(md1) < area(md2))
      hi = md2;
    else
      lo = md1;
  }

  cout << fixed << setprecision(10) << area((lo + hi) / 2) << endl;
  return 0;
};