Submission #1093061

# Submission time Handle Problem Language Result Execution time Memory
1093061 2024-09-25T19:01:19 Z TommasoUlian Mobile (BOI12_mobile) C++17
100 / 100
412 ms 35408 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

vector<pair<double, double>> torri;
ll n, L;

bool canCover(double r) {
    double curr = 0.0; // Current coverage along the highway

    for (int i = 0; i < n; i++) {
        double x = torri[i].first;
        double y = torri[i].second;

        // Calculate the horizontal coverage from the station
        if (abs(y) > r) continue; // Ignore stations that cannot reach the highway

        double dx = sqrt((r * r) - (y * y)); // Width of coverage
        double left = x - dx;  // Left end of coverage
        double right = x + dx; // Right end of coverage

        // If the current position is within the coverage
        if (left <= curr + 1e-6) {
            curr = max(curr, right); // Extend current coverage
        }

        // Early exit if the entire highway is covered
        if (curr >= L) return true;
    }

    return curr >= L; // Final check if we covered the highway
}

void solve() {
    cin >> n >> L;
    torri.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> torri[i].first >> torri[i].second;
    }

    double l = 1.0, r = 2e9; // Reasonable bounds for binary search
    double ans = r;

    // Perform binary search
    while (r - l > 1e-4) {
        double mid = (l + r) / 2;
        if (canCover(mid)) {
            ans = mid; // Update best answer
            r = mid;   // Try for a smaller radius
        } else {
            l = mid; // Increase radius
        }
    }

    cout << setprecision(18) << ans << endl; // Output the result
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    solve();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 2 ms 608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 3 ms 348 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 4 ms 600 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 1628 KB Output is correct
2 Correct 25 ms 2552 KB Output is correct
3 Correct 15 ms 1924 KB Output is correct
4 Correct 34 ms 2660 KB Output is correct
5 Correct 21 ms 1492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 1696 KB Output is correct
2 Correct 21 ms 2332 KB Output is correct
3 Correct 26 ms 2628 KB Output is correct
4 Correct 27 ms 2908 KB Output is correct
5 Correct 38 ms 3156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 1628 KB Output is correct
2 Correct 27 ms 1624 KB Output is correct
3 Correct 25 ms 2648 KB Output is correct
4 Correct 37 ms 3928 KB Output is correct
5 Correct 27 ms 2648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 1884 KB Output is correct
2 Correct 32 ms 3424 KB Output is correct
3 Correct 32 ms 3036 KB Output is correct
4 Correct 43 ms 3924 KB Output is correct
5 Correct 29 ms 3164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 1880 KB Output is correct
2 Correct 33 ms 1880 KB Output is correct
3 Correct 28 ms 3044 KB Output is correct
4 Correct 35 ms 3932 KB Output is correct
5 Correct 32 ms 3300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 162 ms 8280 KB Output is correct
2 Correct 171 ms 8284 KB Output is correct
3 Correct 147 ms 8280 KB Output is correct
4 Correct 172 ms 8284 KB Output is correct
5 Correct 150 ms 14932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 175 ms 8536 KB Output is correct
2 Correct 221 ms 8528 KB Output is correct
3 Correct 136 ms 13892 KB Output is correct
4 Correct 183 ms 17492 KB Output is correct
5 Correct 152 ms 15568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 213 ms 9820 KB Output is correct
2 Correct 191 ms 9820 KB Output is correct
3 Correct 186 ms 18284 KB Output is correct
4 Correct 230 ms 21584 KB Output is correct
5 Correct 196 ms 17596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 219 ms 10064 KB Output is correct
2 Correct 260 ms 9844 KB Output is correct
3 Correct 172 ms 16612 KB Output is correct
4 Correct 233 ms 21464 KB Output is correct
5 Correct 189 ms 18512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 303 ms 11428 KB Output is correct
2 Correct 236 ms 11404 KB Output is correct
3 Correct 234 ms 21332 KB Output is correct
4 Correct 256 ms 24828 KB Output is correct
5 Correct 202 ms 20304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 234 ms 11352 KB Output is correct
2 Correct 326 ms 11404 KB Output is correct
3 Correct 196 ms 19540 KB Output is correct
4 Correct 242 ms 24576 KB Output is correct
5 Correct 210 ms 21500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 261 ms 12892 KB Output is correct
2 Correct 256 ms 12888 KB Output is correct
3 Correct 263 ms 24400 KB Output is correct
4 Correct 294 ms 28500 KB Output is correct
5 Correct 268 ms 23888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 355 ms 12892 KB Output is correct
2 Correct 330 ms 12888 KB Output is correct
3 Correct 243 ms 22300 KB Output is correct
4 Correct 291 ms 28240 KB Output is correct
5 Correct 253 ms 24488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 358 ms 15964 KB Output is correct
2 Correct 291 ms 15960 KB Output is correct
3 Correct 326 ms 30400 KB Output is correct
4 Correct 338 ms 35156 KB Output is correct
5 Correct 328 ms 29520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 351 ms 15960 KB Output is correct
2 Correct 412 ms 16096 KB Output is correct
3 Correct 312 ms 28264 KB Output is correct
4 Correct 390 ms 35408 KB Output is correct
5 Correct 396 ms 30684 KB Output is correct