Submission #1093053

#TimeUsernameProblemLanguageResultExecution timeMemory
1093053TommasoUlianMobile (BOI12_mobile)C++14
100 / 100
480 ms35408 KiB
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#ifndef ONLINE_JUDGE
#define DEBUG(x) cout << #x << " = " << (x) << endl
#else
#define DEBUG(x)
#endif
#define FOR(n) for(int i = 0; i < (n); i++)
#define SORTA(v) sort((v).begin(), (v).end())
#define SORTD(v) sort((v).rbegin(), (v).rend())
#define PRINT(v) for(auto x: (v))cout << x << " "; cout << endl;
#define TWO(n) (1 << (n))
#define INPUT(v) for(auto &x : (v))cin >> x;

typedef long long ll;

using namespace std;

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

// Function to calculate horizontal width
double get_hw(double y, double r) {
    if (abs(y) > r - 1e-6) return -1.0;
    return sqrt((r - y) * (r + y));
}

// Check if given radius R can cover the highway
bool good(double R) {
    double progress = 0.0;
    for (int i = 0; i < n; i++) {
        double x = torri[i].first, y = torri[i].second;
        double hw = get_hw(y, R);  // Horizontal width
        if (hw < 0) continue;  // Station doesn't reach the highway

        double left = x - hw;
        double right = x + hw;
        
        if (left <= progress + 1e-6) {
            progress = max(progress, right);
        }
        if (progress >= L) return true;  // Exit early if highway is covered
    }
    return false;
}

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

    double l = 1, r = 2e9;  // Adjust upper bound based on problem limits
    double ans = r;

    while (r - l > 1e-6) {  // Adjust precision for better accuracy
        double c = (r + l) / 2;
        if (good(c)) {
            ans = c;
            r = c;
        } else {
            l = c;
        }
    }

    cout << setprecision(18) << (l + r) / 2 << endl;  // Output with high precision
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    solve();
    return 0;
}

Compilation message (stderr)

mobile.cpp: In function 'void solve()':
mobile.cpp:56:12: warning: variable 'ans' set but not used [-Wunused-but-set-variable]
   56 |     double ans = r;
      |            ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...