Problem p03004 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for (ll i = 0; i < n; i++)

int main() {
  int n;
  scanf("%d", &n);
  double r1 = -INF, r2 = -INF, r3 = -INF;
  double l1 = INF, l2 = INF, l3 = INF;
  double u1 = -INF, u2 = -INF, u3 = -INF;
  double d1 = INF, d2 = INF, d3 = INF;
  for (int i = 0; i < n; i++) {
    double x, y;
    char d;
    scanf("%lf %lf %c", &x, &y, &d);
    if (d == 'R') {
      r1 = max(r1, x);
      l3 = min(l3, x);
      u2 = max(u2, y);
      d2 = min(d2, y);
    }
    if (d == 'L') {
      r3 = max(r3, x);
      l1 = min(l1, x);
      u2 = max(u2, y);
      d2 = min(d2, y);
    }
    if (d == 'U') {
      r2 = max(r2, x);
      l2 = min(l2, x);
      u1 = max(u1, y);
      d3 = min(d3, y);
    }
    if (d == 'D') {
      r2 = max(r2, x);
      l2 = min(l2, x);
      u3 = max(u3, y);
      d1 = min(d1, y);
    }
  }
  double ans = INF;
  for (double i = 0; i <= 4e8; i += 0.5) {
    ans = min(ans, (max({r1 + i, r2, r3 - i}) - min({l1 - i, l2, l3 + i})) *
                       (max({u1 + i, u2, u3 - i}) - min({d1 - i, d2, d3 + i})));
  }
  printf("%.11lf\n", ans);
}

Fixed submission:
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for (ll i = 0; i < n; i++)

int main() {
  int n;
  scanf("%d", &n);
  double r1 = -INF, r2 = -INF, r3 = -INF;
  double l1 = INF, l2 = INF, l3 = INF;
  double u1 = -INF, u2 = -INF, u3 = -INF;
  double d1 = INF, d2 = INF, d3 = INF;
  for (int i = 0; i < n; i++) {
    double x, y;
    char d;
    scanf("%lf %lf %c", &x, &y, &d);
    if (d == 'R') {
      r1 = max(r1, x);
      l3 = min(l3, x);
      u2 = max(u2, y);
      d2 = min(d2, y);
    }
    if (d == 'L') {
      r3 = max(r3, x);
      l1 = min(l1, x);
      u2 = max(u2, y);
      d2 = min(d2, y);
    }
    if (d == 'U') {
      r2 = max(r2, x);
      l2 = min(l2, x);
      u1 = max(u1, y);
      d3 = min(d3, y);
    }
    if (d == 'D') {
      r2 = max(r2, x);
      l2 = min(l2, x);
      u3 = max(u3, y);
      d1 = min(d1, y);
    }
  }
  double ans = 1e18;
  for (double i = 0; i <= 2e8; i += 0.5) {
    ans = min(ans, (max({r1 + i, r2, r3 - i}) - min({l1 - i, l2, l3 + i})) *
                       (max({u1 + i, u2, u3 - i}) - min({d1 - i, d2, d3 + i})));
  }
  printf("%.11lf\n", ans);
}