Submission #623064

# Submission time Handle Problem Language Result Execution time Memory
623064 2022-08-05T06:50:38 Z 54skyxenon Mobile (BOI12_mobile) C++17
8 / 100
1000 ms 64736 KB
// https://oj.uz/problem/view/BOI12_mobile

#include <bits/stdc++.h>
using namespace std;

#define EPS 0.00001
#define pdd pair<double, double>
#define mp make_pair

int n, l;
vector<double> X, Y;

vector<pdd> merge(vector<pdd>& intervals) {
    sort(intervals.begin(), intervals.end());

    vector<pdd> new_intervals;
    for (auto [start, end] : intervals) {
        if (new_intervals.empty() || new_intervals.back().second < start) {
            new_intervals.push_back(mp(start, end));
        }
        else {
            new_intervals.back().second = max(new_intervals.back().second, end);
        }
    }
    
    return new_intervals;
}

bool ok(double radius) {
    vector<pdd> intervals({mp(0, 0), mp(l, l)});
    
    for (int i = 0; i < n; i++) {
        double x1 = X[i], y1 = Y[i];
    
        double term = (radius * radius) - (y1 * y1);
        if (term >= 0) {
            double term_sqrt = sqrt(term);
            intervals.push_back(mp(x1 - term_sqrt, x1 + term_sqrt));
        }
    }
        
    intervals = merge(intervals);

    for (int i = 0; i < intervals.size() - 1; i++) {
        double midpt = (intervals[i].second + intervals[i + 1].first) / 2;
        if (0 <= midpt && midpt <= l) {
            return true;
        }
    }

    return false;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> l;

    X.resize(n);
    Y.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> X[i] >> Y[i];
    }

    double lo = 0.0;
    double hi = l;

    while (lo + EPS < hi) {
        double mid = (lo + hi) / 2;

        if (!ok(mid)) {
            hi = mid;
        }
        else {
            lo = mid;
        }
    }

    cout << lo << endl;
}

Compilation message

mobile.cpp: In function 'bool ok(double)':
mobile.cpp:44:23: 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 < intervals.size() - 1; i++) {
      |                     ~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
# Verdict Execution time Memory 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
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Incorrect 7 ms 496 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 468 KB Output is correct
2 Incorrect 9 ms 672 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 468 KB Output is correct
2 Incorrect 9 ms 676 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 660 KB Output is correct
2 Incorrect 9 ms 676 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 134 ms 5524 KB Output is correct
2 Incorrect 270 ms 5876 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 40 ms 3404 KB Output is correct
2 Correct 41 ms 3332 KB Output is correct
3 Incorrect 46 ms 3756 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 295 ms 5856 KB Output is correct
2 Incorrect 299 ms 6108 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 315 ms 7144 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 369 ms 7080 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1083 ms 28560 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1097 ms 32436 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1084 ms 40744 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1080 ms 45440 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1078 ms 44744 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1085 ms 50252 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1093 ms 48824 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1085 ms 55032 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1081 ms 56780 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1073 ms 64736 KB Time limit exceeded
2 Halted 0 ms 0 KB -