Submission #6188680


Source Code Expand

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define ALL(x) begin(x), end(x)
using ll = long long;
using namespace std;
template <class T, class U> inline void chmin(T & a, U const & b) { a = min<T>(a, b); }
template <class T, class U> inline void chmax(T & a, U const & b) { a = max<T>(a, b); }

template <typename UnaryPredicate>
int64_t binsearch(int64_t l, int64_t r, UnaryPredicate p) {
    assert (l <= r);
    -- l;
    while (r - l > 1) {
        int64_t m = l + (r - l) / 2;
        (p(m) ? r : l) = m;
    }
    return r;
}


struct desc_t {
    array<ll, 2> incr, decr, fixed;
};

desc_t describe(int n, const vector<ll> & x, const vector<char> & d, char incr, char decr) {
    desc_t a = {
        {{ LLONG_MAX / 3, LLONG_MIN / 3 }},
        {{ LLONG_MAX / 3, LLONG_MIN / 3 }},
        {{ LLONG_MAX / 3, LLONG_MIN / 3 }},
    };
    REP (i, n) {
        if (d[i] == incr) {
            chmin(a.incr[0], x[i]);
            chmax(a.incr[1], x[i]);
        } else if (d[i] == decr) {
            chmin(a.decr[0], x[i]);
            chmax(a.decr[1], x[i]);
        } else {
            chmin(a.fixed[0], x[i]);
            chmax(a.fixed[1], x[i]);
        }
    }
    return a;
}

ll get_doubled_length(const desc_t & a, ll t2) {
    ll l = min(2 * a.incr[0] + t2, min(2 * a.decr[0] - t2, 2 * a.fixed[0]));
    ll r = max(2 * a.incr[1] + t2, max(2 * a.decr[1] - t2, 2 * a.fixed[1]));
    return r - l;
}

long double get_area(const desc_t & ax, const desc_t & ay, ll t2) {
    return get_doubled_length(ax, t2) * get_doubled_length(ay, t2) / 4.l;
}

vector<ll> list_boundaries(const desc_t & a) {
    constexpr ll limit = 1e9;
    vector<ll> b;
    b.push_back(0);
    while (b.back() != limit) {
        ll l = b.back();
        ll c = get_doubled_length(a, l);
        ll d = get_doubled_length(a, l + 1) - get_doubled_length(a, l);
        ll r = binsearch(l, limit, [&](ll t) {
            return get_doubled_length(a, t) != c + d * (t - l);
        });
        b.push_back(r);
    }
    return b;
}

long double solve(int n, const vector<ll> & x, const vector<ll> & y, const vector<char> & d) {
    desc_t ax = describe(n, x, d, 'R', 'L');
    desc_t ay = describe(n, y, d, 'U', 'D');

    vector<ll> bx = list_boundaries(ax);
    vector<ll> by = list_boundaries(ay);
    vector<ll> b;
    copy(ALL(bx), back_inserter(b));
    copy(ALL(by), back_inserter(b));
    sort(ALL(b));
    b.erase(unique(ALL(b)), b.end());

    long double ans = INFINITY;
    REP (i, b.size() - 1) {
        ll l = b[i];
        ll r = b[i + 1];
        chmin(ans, get_area(ax, ay, l));
        chmin(ans, get_area(ax, ay, r));
        binsearch(l, r, [&](ll t) {
            chmin(ans, get_area(ax, ay, t));
            chmin(ans, get_area(ax, ay, t + 1));
            return get_area(ax, ay, t + 1) >= get_area(ax, ay, t);
        });
    }
    return ans;
}

int main() {
    int n; cin >> n;
    vector<ll> x(n), y(n);
    vector<char> d(n);
    REP (i, n) {
        cin >> x[i] >> y[i] >> d[i];
    }
    cout << setprecision(18) << solve(n, x, y, d) << endl;
    return 0;
}

Submission Info

Submission Time
Task F - Minimum Bounding Box
User kimiyuki
Language C++14 (GCC 5.4.1)
Score 600
Code Size 3109 Byte
Status AC
Exec Time 94 ms
Memory 1920 KiB

Judge Result

Set Name All Sample
Score / Max Score 600 / 600 0 / 0
Status
AC × 73
AC × 3
Set Name Test Cases
All sample_00, sample_01, sample_02, testcase_0_0, testcase_0_1, testcase_0_2, testcase_0_3, testcase_0_4, testcase_0_5, testcase_0_6, testcase_0_7, testcase_0_8, testcase_0_9, testcase_1_0, testcase_1_1, testcase_1_10, testcase_1_11, testcase_1_12, testcase_1_13, testcase_1_2, testcase_1_3, testcase_1_4, testcase_1_5, testcase_1_6, testcase_1_7, testcase_1_8, testcase_1_9, testcase_2_0, testcase_2_1, testcase_3_0, testcase_3_1, testcase_3_2, testcase_3_3, testcase_3_4, testcase_4_0, testcase_5_0, testcase_5_1, testcase_5_10, testcase_5_11, testcase_5_12, testcase_5_13, testcase_5_14, testcase_5_2, testcase_5_3, testcase_5_4, testcase_5_5, testcase_5_6, testcase_5_7, testcase_5_8, testcase_5_9, testcase_6_0, testcase_6_1, testcase_6_2, testcase_6_3, testcase_6_4, testcase_7_0, testcase_7_1, testcase_7_10, testcase_7_11, testcase_7_12, testcase_7_13, testcase_7_14, testcase_7_2, testcase_7_3, testcase_7_4, testcase_7_5, testcase_7_6, testcase_7_7, testcase_7_8, testcase_7_9, testcase_998244353, testcase_pair, testcase_powerful
Sample sample_00, sample_01, sample_02
Case Name Status Exec Time Memory
sample_00 AC 1 ms 256 KiB
sample_01 AC 1 ms 256 KiB
sample_02 AC 1 ms 256 KiB
testcase_0_0 AC 1 ms 256 KiB
testcase_0_1 AC 1 ms 256 KiB
testcase_0_2 AC 1 ms 256 KiB
testcase_0_3 AC 1 ms 256 KiB
testcase_0_4 AC 1 ms 256 KiB
testcase_0_5 AC 1 ms 256 KiB
testcase_0_6 AC 1 ms 256 KiB
testcase_0_7 AC 1 ms 256 KiB
testcase_0_8 AC 1 ms 256 KiB
testcase_0_9 AC 1 ms 256 KiB
testcase_1_0 AC 1 ms 256 KiB
testcase_1_1 AC 1 ms 256 KiB
testcase_1_10 AC 1 ms 256 KiB
testcase_1_11 AC 1 ms 256 KiB
testcase_1_12 AC 1 ms 256 KiB
testcase_1_13 AC 1 ms 256 KiB
testcase_1_2 AC 1 ms 256 KiB
testcase_1_3 AC 1 ms 256 KiB
testcase_1_4 AC 1 ms 256 KiB
testcase_1_5 AC 1 ms 256 KiB
testcase_1_6 AC 1 ms 256 KiB
testcase_1_7 AC 1 ms 256 KiB
testcase_1_8 AC 1 ms 256 KiB
testcase_1_9 AC 1 ms 256 KiB
testcase_2_0 AC 1 ms 256 KiB
testcase_2_1 AC 1 ms 256 KiB
testcase_3_0 AC 1 ms 256 KiB
testcase_3_1 AC 1 ms 256 KiB
testcase_3_2 AC 1 ms 256 KiB
testcase_3_3 AC 1 ms 256 KiB
testcase_3_4 AC 1 ms 256 KiB
testcase_4_0 AC 42 ms 1920 KiB
testcase_5_0 AC 31 ms 768 KiB
testcase_5_1 AC 55 ms 1280 KiB
testcase_5_10 AC 50 ms 1152 KiB
testcase_5_11 AC 42 ms 1024 KiB
testcase_5_12 AC 1 ms 256 KiB
testcase_5_13 AC 45 ms 1024 KiB
testcase_5_14 AC 25 ms 640 KiB
testcase_5_2 AC 42 ms 1024 KiB
testcase_5_3 AC 26 ms 640 KiB
testcase_5_4 AC 14 ms 512 KiB
testcase_5_5 AC 77 ms 1664 KiB
testcase_5_6 AC 34 ms 896 KiB
testcase_5_7 AC 55 ms 1280 KiB
testcase_5_8 AC 83 ms 1792 KiB
testcase_5_9 AC 22 ms 640 KiB
testcase_6_0 AC 57 ms 1920 KiB
testcase_6_1 AC 57 ms 1920 KiB
testcase_6_2 AC 62 ms 1920 KiB
testcase_6_3 AC 56 ms 1920 KiB
testcase_6_4 AC 56 ms 1920 KiB
testcase_7_0 AC 1 ms 256 KiB
testcase_7_1 AC 1 ms 256 KiB
testcase_7_10 AC 1 ms 256 KiB
testcase_7_11 AC 1 ms 256 KiB
testcase_7_12 AC 1 ms 256 KiB
testcase_7_13 AC 1 ms 256 KiB
testcase_7_14 AC 1 ms 256 KiB
testcase_7_2 AC 1 ms 256 KiB
testcase_7_3 AC 1 ms 256 KiB
testcase_7_4 AC 1 ms 256 KiB
testcase_7_5 AC 1 ms 256 KiB
testcase_7_6 AC 1 ms 256 KiB
testcase_7_7 AC 1 ms 256 KiB
testcase_7_8 AC 1 ms 256 KiB
testcase_7_9 AC 1 ms 256 KiB
testcase_998244353 AC 94 ms 1920 KiB
testcase_pair AC 1 ms 256 KiB
testcase_powerful AC 1 ms 256 KiB