답안 #732385

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
732385 2023-04-29T03:18:58 Z uy842003 Mobile (BOI12_mobile) C++17
50 / 100
1000 ms 48168 KB
#include <bits/stdc++.h>
using namespace std;

const double eps = 1e-4;

bool cmp_less(double a, double b) {
    return a + eps < b;
}

bool cmp_less_equal(double a, double b) {
    return a < b + eps;
}

bool cmp_range(const pair<double, double> &p1, const pair<double, double> &p2) {
    return cmp_less(p1.first, p2.first);
}

bool inside(double l, double r, double m) {
    return cmp_less_equal(l, m) && cmp_less_equal(m, r);
}

int main() {

    int n;
    double len;
    cin >> n >> len;
    vector<pair<double, double>> cor(n);
    for (int i = 0; i < n; i++)
        cin >> cor[i].first >> cor[i].second;
    double l = 0, r = 2e9 + 7, m;
    while (cmp_less(l, r)) {
        m = (l + r) / 2;
        // cout << "@m " << m << endl;
        vector<pair<double, double>> range, real_range;
        for (int i = 0; i < n; i++) {
            if (cmp_less_equal(m, abs(cor[i].second))) continue;
            double dx = sqrt(m * m - cor[i].second * cor[i].second);
            range.push_back({cor[i].first - dx, cor[i].first + dx});
        }
        // cout << "dx ok" << endl;
        sort(range.begin(), range.end(), cmp_range);
        pair<double, double> cur_range = {-1, -1};
        if (range.size() > 0) cur_range = *range.begin();
        for (int i = 0; i < range.size(); i++) {
            if (inside(cur_range.first, cur_range.second, range[i].first) && cmp_less(cur_range.second, range[i].second))
                cur_range.second = range[i].second;
            if (!inside(cur_range.first, cur_range.second, range[i].first) || i + 1 == range.size()) {
                real_range.push_back(cur_range);
                cur_range = range[i];
            }
        }
        // cout << "real range ok" << endl;
        bool iok = false;
        for (int i = 0; i < real_range.size(); i++) {
            if (inside(real_range[i].first, real_range[i].second, 0) && inside(real_range[i].first, real_range[i].second, len)) {
                iok = true;
                break;
            }
        }
        if (iok)
            r = m;
        else
            l = m + eps;
        // cout << "check inside ok" << endl;
    }
    cout << setprecision(3) << fixed;
    cout << r << endl;

    return 0;
}

Compilation message

mobile.cpp: In function 'int main()':
mobile.cpp:44:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<double, double> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |         for (int i = 0; i < range.size(); i++) {
      |                         ~~^~~~~~~~~~~~~~
mobile.cpp:47:85: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<double, double> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |             if (!inside(cur_range.first, cur_range.second, range[i].first) || i + 1 == range.size()) {
      |                                                                               ~~~~~~^~~~~~~~~~~~~~~
mobile.cpp:54:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<double, double> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |         for (int i = 0; i < real_range.size(); i++) {
      |                         ~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 336 KB Output is correct
2 Correct 9 ms 340 KB Output is correct
3 Correct 6 ms 340 KB Output is correct
4 Correct 8 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 580 KB Output is correct
2 Correct 20 ms 580 KB Output is correct
3 Correct 25 ms 580 KB Output is correct
4 Correct 13 ms 580 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 580 KB Output is correct
2 Correct 18 ms 596 KB Output is correct
3 Correct 20 ms 596 KB Output is correct
4 Correct 10 ms 612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 580 KB Output is correct
2 Correct 19 ms 580 KB Output is correct
3 Correct 22 ms 588 KB Output is correct
4 Correct 13 ms 580 KB Output is correct
5 Correct 13 ms 580 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 222 ms 4728 KB Output is correct
2 Correct 417 ms 4792 KB Output is correct
3 Correct 251 ms 3128 KB Output is correct
4 Correct 187 ms 4744 KB Output is correct
5 Correct 133 ms 2920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 217 ms 4824 KB Output is correct
2 Correct 201 ms 4552 KB Output is correct
3 Correct 207 ms 4888 KB Output is correct
4 Correct 180 ms 4836 KB Output is correct
5 Correct 177 ms 5080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 360 ms 5236 KB Output is correct
2 Correct 492 ms 5152 KB Output is correct
3 Correct 563 ms 5040 KB Output is correct
4 Correct 186 ms 5528 KB Output is correct
5 Correct 242 ms 5140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 487 ms 5532 KB Output is correct
2 Correct 573 ms 5608 KB Output is correct
3 Correct 673 ms 5512 KB Output is correct
4 Correct 177 ms 5396 KB Output is correct
5 Correct 259 ms 5556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 484 ms 5516 KB Output is correct
2 Correct 577 ms 5840 KB Output is correct
3 Correct 663 ms 5504 KB Output is correct
4 Correct 187 ms 5408 KB Output is correct
5 Correct 268 ms 5544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1042 ms 24260 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1068 ms 24284 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1078 ms 35664 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1062 ms 35612 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1066 ms 38668 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1066 ms 38648 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1077 ms 41828 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1060 ms 41772 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1069 ms 48168 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1071 ms 16580 KB Time limit exceeded
2 Halted 0 ms 0 KB -