Problem p03004 (C++)

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

using namespace std;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define FORR(i, m, n) for (ll i = m; i >= n; i--)
#define REPO(i, n) for (ll i = 1; i <= n; i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(), n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>

ll n;
double x[110000], y[110000];
char d[110000];
const double EPS = 1e-10;

double f(double a) {
  double xmx = 1e8 * 3 * -1, xmi = 1e8 * 3, ymx = 1e8 * 3 * -1, ymi = 1e8 * 3;
  REP(i, n) {
    double nowx = x[i], nowy = y[i];
    if (d[i] == 'R')
      nowx += a;
    if (d[i] == 'L')
      nowx -= a;
    if (d[i] == 'U')
      nowy += a;
    if (d[i] == 'D')
      nowy -= a;
    xmx = max(xmx, nowx);
    xmi = min(xmi, nowx);
    ymx = max(ymx, nowy);
    ymi = min(ymi, nowy);
    // cout << nowx << " " << nowy << endl;
  }
  // cout << xmx << " " << xmi << " " << ymx << " " << ymi << endl;
  return (xmx - xmi) * (ymx - ymi);
}

int main() {
  cin >> n;
  REP(i, n) { cin >> x[i] >> y[i] >> d[i]; }
  double low = 0.0, high = 1e8 * 3;
  while (high - low > EPS) {
    double width = high - low, ml = low + width / 3.0,
           mr = low + 2.0 * width / 3.0;
    if (f(ml) <= f(mr)) {
      high = mr;
    } else {
      low = ml;
    }
  }
  // cout << (high + low) * 0.5 << endl;
  cout << setprecision(10) << fixed << f((high + low) * 0.5) << endl;
}


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

using namespace std;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define FORR(i, m, n) for (ll i = m; i >= n; i--)
#define REPO(i, n) for (ll i = 1; i <= n; i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(), n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>

ll n;
double x[110000], y[110000];
char d[110000];
const double EPS = 1e-10;

double f(double a) {
  double xmx = 1e8 * 3 * -1, xmi = 1e8 * 3, ymx = 1e8 * 3 * -1, ymi = 1e8 * 3;
  REP(i, n) {
    double nowx = x[i], nowy = y[i];
    if (d[i] == 'R')
      nowx += a;
    if (d[i] == 'L')
      nowx -= a;
    if (d[i] == 'U')
      nowy += a;
    if (d[i] == 'D')
      nowy -= a;
    xmx = max(xmx, nowx);
    xmi = min(xmi, nowx);
    ymx = max(ymx, nowy);
    ymi = min(ymi, nowy);
    // cout << nowx << " " << nowy << endl;
  }
  // cout << xmx << " " << xmi << " " << ymx << " " << ymi << endl;
  return (xmx - xmi) * (ymx - ymi);
}

int main() {
  cin >> n;
  REP(i, n) { cin >> x[i] >> y[i] >> d[i]; }
  double low = 0.0, high = 1e8 * 3;
  REP(i, 300) {
    double width = high - low, ml = low + width / 3.0,
           mr = low + 2.0 * width / 3.0;
    if (f(ml) <= f(mr)) {
      high = mr;
    } else {
      low = ml;
    }
  }
  // cout << (high + low) * 0.5 << endl;
  cout << setprecision(10) << fixed << f((high + low) * 0.5) << endl;
}