Submission #732395

# Submission time Handle Problem Language Result Execution time Memory
732395 2023-04-29T03:35:34 Z uy842003 Mobile (BOI12_mobile) C++17
50 / 100
1000 ms 48016 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_equal(double a, double b) {
    return abs(a - b) < eps;
}

bool cmp_less_equal(double a, double b) {
    return cmp_less(a, b) || cmp_equal(a, b);
}

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

int main() {

    int n;
    double len;
    cin >> n >> len;
    pair<double, double> *cor = new pair<double, double>[n];
    // 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;
        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});
        }
        sort(range.begin(), range.end(), cmp_range);
        pair<double, double> cur_range = {-1, -1};
        if (range.size() > 0) cur_range = range[0];
        for (int i = 0; i < range.size(); i++) {
            if (cmp_less_equal(range[i].first, cur_range.second) && cmp_less(cur_range.second, range[i].second))
                cur_range.second = range[i].second;
            if (!cmp_less_equal(range[i].first, cur_range.second) || i + 1 == range.size()) {
                real_range.push_back(cur_range);
                cur_range = range[i];
            }
        }
        bool iok = false;
        for (int i = 0; i < real_range.size(); i++) {
            if (cmp_less_equal(real_range[i].first, 0) && cmp_less_equal(len, real_range[i].second)) {
                iok = true;
                break;
            }
        }
        if (iok)
            r = m;
        else
            l = m + eps;
    }
    cout << setprecision(3) << fixed;
    cout << r << endl;
    delete [] cor;

    return 0;
}

Compilation message

mobile.cpp: In function 'int main()':
mobile.cpp:43: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]
   43 |         for (int i = 0; i < range.size(); i++) {
      |                         ~~^~~~~~~~~~~~~~
mobile.cpp:46:76: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<double, double> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |             if (!cmp_less_equal(range[i].first, cur_range.second) || i + 1 == range.size()) {
      |                                                                      ~~~~~~^~~~~~~~~~~~~~~
mobile.cpp:52: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]
   52 |         for (int i = 0; i < real_range.size(); i++) {
      |                         ~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 340 KB Output is correct
2 Correct 8 ms 340 KB Output is correct
3 Correct 7 ms 340 KB Output is correct
4 Correct 8 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 580 KB Output is correct
2 Correct 20 ms 580 KB Output is correct
3 Correct 20 ms 580 KB Output is correct
4 Correct 12 ms 580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 596 KB Output is correct
2 Correct 18 ms 604 KB Output is correct
3 Correct 20 ms 580 KB Output is correct
4 Correct 11 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 596 KB Output is correct
2 Correct 19 ms 596 KB Output is correct
3 Correct 22 ms 596 KB Output is correct
4 Correct 10 ms 580 KB Output is correct
5 Correct 13 ms 652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 234 ms 4784 KB Output is correct
2 Correct 419 ms 4816 KB Output is correct
3 Correct 254 ms 3020 KB Output is correct
4 Correct 173 ms 4752 KB Output is correct
5 Correct 134 ms 2896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 231 ms 4832 KB Output is correct
2 Correct 190 ms 4580 KB Output is correct
3 Correct 208 ms 4916 KB Output is correct
4 Correct 182 ms 4948 KB Output is correct
5 Correct 184 ms 5064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 365 ms 5128 KB Output is correct
2 Correct 441 ms 4948 KB Output is correct
3 Correct 571 ms 5016 KB Output is correct
4 Correct 176 ms 5392 KB Output is correct
5 Correct 247 ms 5144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 501 ms 5512 KB Output is correct
2 Correct 552 ms 5808 KB Output is correct
3 Correct 703 ms 5500 KB Output is correct
4 Correct 177 ms 5408 KB Output is correct
5 Correct 257 ms 5504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 434 ms 5612 KB Output is correct
2 Correct 555 ms 5608 KB Output is correct
3 Correct 702 ms 5488 KB Output is correct
4 Correct 193 ms 5396 KB Output is correct
5 Correct 278 ms 5484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1070 ms 24272 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1071 ms 24276 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1061 ms 35652 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1056 ms 35540 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1075 ms 38740 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1077 ms 38652 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1047 ms 41964 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1041 ms 41780 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1082 ms 48016 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1074 ms 32432 KB Time limit exceeded
2 Halted 0 ms 0 KB -