답안 #481876

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
481876 2021-10-22T05:03:36 Z sberens Mobile (BOI12_mobile) C++17
90 / 100
1000 ms 15972 KB
#pragma GCC optimize ("Ofast,fast-math,inline,avx2")

#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) > 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

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
            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
        array<ld, 2> highway{0, (ld) l};
        for (auto interval : intervals) {
            if (a_contains_b(interval, highway)) return true;
        }
        return false;

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

}

Compilation message

mobile.cpp:2:52: warning: bad option '-favx2' to pragma 'optimize' [-Wpragmas]
    2 | #pragma GCC optimize ("Ofast,fast-math,inline,avx2")
      |                                                    ^
mobile.cpp:52:104: warning: bad option '-favx2' to attribute 'optimize' [-Wattributes]
   52 | IN discrete_binary_search(function<bool(IN)> predicate, IN low = 0, IN high = numeric_limits<IN>::max()) {
      |                                                                                                        ^
mobile.cpp:64:57: warning: bad option '-favx2' to attribute 'optimize' [-Wattributes]
   64 | inline bool a_contains_b(array<ld, 2> a,  array<ld, 2> b) {
      |                                                         ^
mobile.cpp:68:10: warning: bad option '-favx2' to attribute 'optimize' [-Wattributes]
   68 | int main() {
      |          ^
mobile.cpp: In function 'int main()':
mobile.cpp:78:82: warning: bad option '-favx2' to attribute 'optimize' [-Wattributes]
   78 |     cout << fixed << setprecision(4) <<  discrete_binary_search<ld>([&](ld d) -> bool {
      |                                                                                  ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 3 ms 332 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Correct 4 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 408 KB Output is correct
2 Correct 8 ms 332 KB Output is correct
3 Correct 6 ms 332 KB Output is correct
4 Correct 4 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 332 KB Output is correct
2 Correct 7 ms 408 KB Output is correct
3 Correct 5 ms 332 KB Output is correct
4 Correct 3 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 416 KB Output is correct
2 Correct 6 ms 332 KB Output is correct
3 Correct 5 ms 332 KB Output is correct
4 Correct 3 ms 332 KB Output is correct
5 Correct 5 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 78 ms 1492 KB Output is correct
2 Correct 112 ms 1604 KB Output is correct
3 Correct 61 ms 1148 KB Output is correct
4 Correct 43 ms 1508 KB Output is correct
5 Correct 36 ms 1104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 1484 KB Output is correct
2 Correct 45 ms 1432 KB Output is correct
3 Correct 48 ms 1600 KB Output is correct
4 Correct 47 ms 1560 KB Output is correct
5 Correct 42 ms 1672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 99 ms 1696 KB Output is correct
2 Correct 96 ms 1620 KB Output is correct
3 Correct 84 ms 1612 KB Output is correct
4 Correct 57 ms 1868 KB Output is correct
5 Correct 64 ms 1720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 116 ms 1896 KB Output is correct
2 Correct 115 ms 1880 KB Output is correct
3 Correct 100 ms 1868 KB Output is correct
4 Correct 45 ms 1892 KB Output is correct
5 Correct 60 ms 1868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 115 ms 1868 KB Output is correct
2 Correct 116 ms 1980 KB Output is correct
3 Correct 127 ms 1900 KB Output is correct
4 Correct 52 ms 1880 KB Output is correct
5 Correct 57 ms 1868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 576 ms 8264 KB Output is correct
2 Correct 624 ms 8140 KB Output is correct
3 Correct 573 ms 8140 KB Output is correct
4 Correct 203 ms 8140 KB Output is correct
5 Correct 298 ms 8148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 618 ms 8148 KB Output is correct
2 Correct 540 ms 8536 KB Output is correct
3 Correct 477 ms 8144 KB Output is correct
4 Correct 217 ms 8148 KB Output is correct
5 Correct 278 ms 8144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 771 ms 9712 KB Output is correct
2 Correct 725 ms 9788 KB Output is correct
3 Correct 688 ms 9716 KB Output is correct
4 Correct 236 ms 9708 KB Output is correct
5 Correct 366 ms 9708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 698 ms 9844 KB Output is correct
2 Correct 601 ms 10016 KB Output is correct
3 Correct 572 ms 9700 KB Output is correct
4 Correct 244 ms 9708 KB Output is correct
5 Correct 380 ms 9700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 779 ms 11392 KB Output is correct
2 Correct 829 ms 11400 KB Output is correct
3 Correct 789 ms 11280 KB Output is correct
4 Correct 339 ms 11276 KB Output is correct
5 Correct 417 ms 11408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 818 ms 11276 KB Output is correct
2 Correct 675 ms 11584 KB Output is correct
3 Correct 682 ms 11324 KB Output is correct
4 Correct 299 ms 11332 KB Output is correct
5 Correct 370 ms 11280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 922 ms 12840 KB Output is correct
2 Correct 952 ms 12840 KB Output is correct
3 Correct 906 ms 12860 KB Output is correct
4 Correct 345 ms 12876 KB Output is correct
5 Correct 460 ms 12840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 961 ms 12836 KB Output is correct
2 Correct 773 ms 13092 KB Output is correct
3 Correct 786 ms 12964 KB Output is correct
4 Correct 348 ms 12840 KB Output is correct
5 Correct 421 ms 12828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1093 ms 15960 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1095 ms 15972 KB Time limit exceeded
2 Halted 0 ms 0 KB -