Submission #481860

# Submission time Handle Problem Language Result Execution time Memory
481860 2021-10-22T04:06:55 Z sberens Mobile (BOI12_mobile) C++17
65 / 100
1000 ms 47328 KB
#pragma GCC optimize ("Ofast,fast-math")

#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename K> using hset = gp_hash_table<K, null_type>;
template <typename K, typename V> using hmap = gp_hash_table<K, V>;


using namespace std;

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define smax(x, y) (x = max(x, y))
#define smin(x, y) (x = min(x, y))

using ld = long double;
using ll = long long;

template <typename T>
using vv = vector<vector<T>>;

using vi = vector<int>;
using ii = array<int, 2>;
using vii = vector<ii>;
using vvi = vv<int>;

using vll = vector<ll>;
using l2 = array<int, 2>;
using vl2 = vector<l2>;
using vvll = vv<ll>;

template <typename T>
using minq = priority_queue<T, vector<T>, greater<T>>;
template <typename T>
using maxq = priority_queue<T>;

const ll M = 1000000007;

#ifndef REFERENCE_DISCRETE_BINARY_SEARCH_H
#define REFERENCE_DISCRETE_BINARY_SEARCH_H


#include <iostream>
#include <functional>


template<typename IN>
IN discrete_binary_search(function<bool(IN)> predicate, IN low = 0, IN high = numeric_limits<IN>::max()) {
    while (fabs(high - low) > 2e-3) {
        IN middle = low + (high - low) / 2; // todo std::midpoint in cpp 2020
        if (predicate(middle))
            high = middle;
        else low = middle;
    }
    return low;
}

#endif //REFERENCE_DISCRETE_BINARY_SEARCH_H

inline bool a_contains_b(array<ld, 2> a,  array<ld, 2> b) {
    return a[0] <= b[0] && b[1] <= a[1];
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, l;
    cin >> n >> l;
    vll x(n), y(n);
    for (int i = 0; i < n; ++i) {
        cin >> x[i] >> y[i];
    }

    cout << fixed << setprecision(4) <<  discrete_binary_search<ld>([&](ld d) -> bool {
        // is there a point with min distance > d
        // equivalently, is every point within distance d

        vector<array<ld, 2>> intervals;
        intervals.reserve(n);
        // add to intervals
        for (int i = 0; i < n; ++i) {
            if (abs(y[i]) > d) continue;
            ld dx = sqrt(d * d - y[i] * y[i]);
            // get rid of nested intervals
            array<ld, 2> new_interval{x[i] - dx, x[i] + dx};
            while (!intervals.empty() && a_contains_b(new_interval, intervals.back())) {
                intervals.pop_back();
            }
            if (!(!intervals.empty() && a_contains_b(intervals.back(), new_interval)))
                intervals.pb({x[i] - dx, x[i] + dx});
        }

        // merge intervals
        vector<array<ld, 2>> merged;
        merged.reserve(n);
        for (auto [s, e] : intervals) {
            if (!merged.empty() && s <= merged.back()[1]) smax(merged.back()[1], e);
            else merged.pb({s, e});
        }
        // check interval spans whole highway
        return any_of(all(merged), [&](array<ld, 2> interval) -> bool {return a_contains_b(interval, {0, (ld) l});});

    }, 0, sqrt(1e18 + 4 * 1e18 + 1e10)) << '\n';

}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 364 KB Output is correct
2 Correct 5 ms 432 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Correct 4 ms 420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 476 KB Output is correct
2 Correct 8 ms 560 KB Output is correct
3 Correct 4 ms 424 KB Output is correct
4 Correct 4 ms 536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 492 KB Output is correct
2 Correct 8 ms 552 KB Output is correct
3 Correct 3 ms 416 KB Output is correct
4 Correct 4 ms 524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 556 KB Output is correct
2 Correct 9 ms 712 KB Output is correct
3 Correct 5 ms 428 KB Output is correct
4 Correct 3 ms 496 KB Output is correct
5 Correct 4 ms 420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 103 ms 3672 KB Output is correct
2 Correct 67 ms 3184 KB Output is correct
3 Correct 72 ms 2900 KB Output is correct
4 Correct 35 ms 2148 KB Output is correct
5 Correct 33 ms 1244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 1904 KB Output is correct
2 Correct 46 ms 2540 KB Output is correct
3 Correct 47 ms 3276 KB Output is correct
4 Correct 41 ms 2212 KB Output is correct
5 Correct 36 ms 2076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 147 ms 4652 KB Output is correct
2 Correct 68 ms 3148 KB Output is correct
3 Correct 97 ms 4012 KB Output is correct
4 Correct 42 ms 2268 KB Output is correct
5 Correct 53 ms 2272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 113 ms 3048 KB Output is correct
2 Correct 72 ms 3148 KB Output is correct
3 Correct 62 ms 2448 KB Output is correct
4 Correct 37 ms 2320 KB Output is correct
5 Correct 56 ms 3944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 181 ms 5172 KB Output is correct
2 Correct 73 ms 3148 KB Output is correct
3 Correct 62 ms 2444 KB Output is correct
4 Correct 41 ms 2288 KB Output is correct
5 Correct 57 ms 3816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 840 ms 23900 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 297 ms 8492 KB Output is correct
2 Correct 676 ms 23680 KB Output is correct
3 Correct 316 ms 11160 KB Output is correct
4 Correct 180 ms 8656 KB Output is correct
5 Correct 209 ms 10948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1016 ms 28696 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 345 ms 9956 KB Output is correct
2 Correct 790 ms 28284 KB Output is correct
3 Correct 327 ms 11796 KB Output is correct
4 Correct 206 ms 10224 KB Output is correct
5 Correct 246 ms 12900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1088 ms 33352 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 411 ms 11500 KB Output is correct
2 Correct 895 ms 32976 KB Output is correct
3 Correct 429 ms 15276 KB Output is correct
4 Correct 241 ms 11916 KB Output is correct
5 Correct 290 ms 14996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1087 ms 38060 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 445 ms 13048 KB Output is correct
2 Execution timed out 1010 ms 37504 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1084 ms 47328 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 551 ms 16128 KB Output is correct
2 Execution timed out 1087 ms 46648 KB Time limit exceeded
3 Halted 0 ms 0 KB -