Submission #481886

# Submission time Handle Problem Language Result Execution time Memory
481886 2021-10-22T05:19:05 Z sberens Mobile (BOI12_mobile) C++17
100 / 100
776 ms 15980 KB
#pragma GCC optimize ("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 = 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) > 1e-4) {
        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

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]);
            ld s1 = x[i] - dx, e1 = x[i] + dx;
            // can merge in place
            while (!intervals.empty()) {
                auto & [s2, e2] = intervals.back();
                if (max(s1, s2) <= min(e1, e2)) {
                    smin(s1, s2);
                    smax(e1, e2);
                    intervals.pop_back();
                } else break;
            }
            intervals.pb({s1, e1});
        }

        // check interval spans whole highway
        for (auto [s, e] : intervals) {
            if (s <= 0 && l <= e) return true;
        }
        return false;

    }, 0, 4e9) << '\n';

}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 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 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 332 KB Output is correct
2 Correct 4 ms 332 KB Output is correct
3 Correct 4 ms 332 KB Output is correct
4 Correct 3 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 332 KB Output is correct
2 Correct 4 ms 332 KB Output is correct
3 Correct 4 ms 332 KB Output is correct
4 Correct 4 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 332 KB Output is correct
2 Correct 5 ms 388 KB Output is correct
3 Correct 4 ms 332 KB Output is correct
4 Correct 3 ms 332 KB Output is correct
5 Correct 3 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 1484 KB Output is correct
2 Correct 58 ms 1516 KB Output is correct
3 Correct 35 ms 1100 KB Output is correct
4 Correct 29 ms 1512 KB Output is correct
5 Correct 27 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 1612 KB Output is correct
2 Correct 37 ms 1416 KB Output is correct
3 Correct 35 ms 1608 KB Output is correct
4 Correct 31 ms 1564 KB Output is correct
5 Correct 32 ms 1696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 63 ms 1612 KB Output is correct
2 Correct 63 ms 1612 KB Output is correct
3 Correct 58 ms 1612 KB Output is correct
4 Correct 45 ms 1892 KB Output is correct
5 Correct 41 ms 1712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 77 ms 1868 KB Output is correct
2 Correct 76 ms 1884 KB Output is correct
3 Correct 64 ms 1896 KB Output is correct
4 Correct 49 ms 1924 KB Output is correct
5 Correct 43 ms 1884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 80 ms 2004 KB Output is correct
2 Correct 78 ms 1888 KB Output is correct
3 Correct 66 ms 1868 KB Output is correct
4 Correct 37 ms 1868 KB Output is correct
5 Correct 44 ms 1924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 356 ms 8144 KB Output is correct
2 Correct 380 ms 8144 KB Output is correct
3 Correct 413 ms 8144 KB Output is correct
4 Correct 162 ms 8140 KB Output is correct
5 Correct 235 ms 8140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 431 ms 8140 KB Output is correct
2 Correct 350 ms 8140 KB Output is correct
3 Correct 315 ms 8152 KB Output is correct
4 Correct 171 ms 8140 KB Output is correct
5 Correct 190 ms 8144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 440 ms 9804 KB Output is correct
2 Correct 466 ms 9712 KB Output is correct
3 Correct 449 ms 9712 KB Output is correct
4 Correct 208 ms 9700 KB Output is correct
5 Correct 268 ms 9724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 479 ms 9704 KB Output is correct
2 Correct 415 ms 9856 KB Output is correct
3 Correct 380 ms 9676 KB Output is correct
4 Correct 210 ms 9712 KB Output is correct
5 Correct 235 ms 9704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 515 ms 11276 KB Output is correct
2 Correct 615 ms 11272 KB Output is correct
3 Correct 552 ms 11212 KB Output is correct
4 Correct 240 ms 11280 KB Output is correct
5 Correct 300 ms 11264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 559 ms 11196 KB Output is correct
2 Correct 467 ms 11212 KB Output is correct
3 Correct 460 ms 11276 KB Output is correct
4 Correct 236 ms 11272 KB Output is correct
5 Correct 278 ms 11280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 590 ms 12840 KB Output is correct
2 Correct 620 ms 12840 KB Output is correct
3 Correct 610 ms 12836 KB Output is correct
4 Correct 282 ms 12840 KB Output is correct
5 Correct 359 ms 12836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 650 ms 12876 KB Output is correct
2 Correct 545 ms 12860 KB Output is correct
3 Correct 504 ms 12836 KB Output is correct
4 Correct 263 ms 12748 KB Output is correct
5 Correct 321 ms 12844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 731 ms 15976 KB Output is correct
2 Correct 762 ms 15972 KB Output is correct
3 Correct 757 ms 15980 KB Output is correct
4 Correct 343 ms 15976 KB Output is correct
5 Correct 431 ms 15980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 776 ms 15972 KB Output is correct
2 Correct 634 ms 15980 KB Output is correct
3 Correct 635 ms 15948 KB Output is correct
4 Correct 375 ms 15980 KB Output is correct
5 Correct 386 ms 15972 KB Output is correct