답안 #671371

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
671371 2022-12-13T01:46:48 Z havingfun854 Mobile (BOI12_mobile) C++11
75 / 100
1000 ms 24628 KB
// https://oj.uz/problem/view/BOI12_mobile
#include <bits/stdc++.h>
using namespace std;

#define forint(i, from, toinc) for (int i = from; i <= toinc; ++i)
#define sq(x) (x)*(x)
#define all(x) x.begin(), x.end()

void fio()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
#ifdef USEFILE
    freopen("mobile.in", "r", stdin);
    freopen("mobile.out", "w", stdout);
#endif
}

/*
    some observations:

    if we have 2 towers with the same x, (x, y1) and (x, y2),
    we only need to keep the one with the smallest abs y value,
    let's say |y1| <= |y2|, then we can safely forget (x, y2), because for any
    point on the x axis, it will always be closer (<=) to (x, y1) than to (x, y2).

    we do a simple binary search on distance d to see if all points between [0,L]
    can be covered by d.
 */

struct Point {
    int x,y;
};
struct Range {
    double from, to;
    bool operator<(const Range &o) const {
        return from == o.from ? to > o.to : from < o.from;
        // same from rank the one with the larger to first
    }
};

int tcnt;                   // tower count
vector<Point> towers;
int len;                    // all points on (0,0) to (len,0) to the towers
vector<Range> ranges;
int rcnt;

void debug()
{
    cerr << "highway from (0,0) to (" << len << ",0)" << endl;

    cerr << tcnt << " towers:";
    forint(i, 0, tcnt-1) {
        cerr << " " << towers[i].x << "," << towers[i].y;
    }
    cerr << endl;

    cerr << rcnt << " ranges:";
    forint(i, 0, rcnt-1) {
        cerr << " [" << ranges[i].from << "," << ranges[i].to << "]";
    }
    cerr << endl;
}

void rdata()
{
    cin >> tcnt >> len;

    int lastx, lasty;       // lasty >= 0
    cin >> lastx >> lasty;
    lasty = abs(lasty);

    forint(i, 1, tcnt-1) {
        int x, y;
        cin >> x >> y;
        if (x != lastx) {
            towers.push_back({lastx, lasty});
            lastx = x;
            lasty = abs(y);
        } else if (abs(y) < abs(lasty)) {
            lasty = abs(y);
        }
        if (i == tcnt-1) {
            towers.push_back({lastx, lasty});
        }
    }

    tcnt = (int)towers.size();
}


bool can_cover(double d)
{
    ranges.clear();

    forint(i, 0, tcnt-1) {
        double x = towers[i].x;
        double y = towers[i].y;
        if (d > y) {
            double dx = sqrt(sq(d) - sq(y));
            if (x-dx > len || x+dx < 0) continue;
            ranges.push_back({x-dx, x+dx});
        }
    }
    rcnt = (int)ranges.size();

    sort(all(ranges));

#ifdef DEBUG
    debug();
#endif

    double right = 0;
    forint(i, 0, rcnt-1) {
        if (ranges[i].from <= right) {
            right = max(ranges[i].to, right);
            if (right >= len) break;
        } else {
            break;
        }
    }

    bool res = right >= len;
#ifdef DEBUG
    cerr << "d=" << d << " can" << (res ? "" : "not") << " cover all" << endl;
#endif
    return res;
}

inline
double d2(int i, double x)
{
    return sq(towers[i].x - x) + sq(towers[i].y);
}

int main()
{
    fio();
    rdata();
#ifdef DEBUG
    debug();
#endif

    double dends2 = d2(0, 0);
    dends2 = max(dends2, d2(0, len));
    dends2 = max(dends2, d2(tcnt-1, 0));
    dends2 = max(dends2, d2(tcnt-1, len));

    double dmax = sqrt(dends2);

    double d = dmax+1;
    for (double step = dmax; step > 1e-4; step /= 2) {
        while (d-step > 0 && can_cover(d-step)) {
            d -= step;
        }
    }
    cout << fixed << setprecision(3) << d << '\n';

    return 0;
}
# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 5 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 3 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 340 KB Output is correct
2 Correct 18 ms 504 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 3 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 14 ms 504 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 468 KB Output is correct
2 Correct 12 ms 504 KB Output is correct
3 Correct 3 ms 340 KB Output is correct
4 Correct 3 ms 468 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 3020 KB Output is correct
2 Correct 189 ms 1904 KB Output is correct
3 Correct 167 ms 1880 KB Output is correct
4 Correct 34 ms 3092 KB Output is correct
5 Correct 6 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 516 KB Output is correct
2 Correct 23 ms 1672 KB Output is correct
3 Correct 30 ms 2412 KB Output is correct
4 Correct 32 ms 3112 KB Output is correct
5 Correct 51 ms 3156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 249 ms 3156 KB Output is correct
2 Correct 169 ms 1820 KB Output is correct
3 Correct 452 ms 2348 KB Output is correct
4 Correct 51 ms 3284 KB Output is correct
5 Correct 17 ms 1088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 133 ms 1720 KB Output is correct
2 Correct 157 ms 1768 KB Output is correct
3 Correct 97 ms 760 KB Output is correct
4 Correct 46 ms 3296 KB Output is correct
5 Correct 38 ms 3104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 144 ms 3260 KB Output is correct
2 Correct 139 ms 1728 KB Output is correct
3 Correct 108 ms 824 KB Output is correct
4 Correct 43 ms 3284 KB Output is correct
5 Correct 34 ms 3148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1069 ms 12540 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 107 ms 752 KB Output is correct
2 Correct 598 ms 12480 KB Output is correct
3 Correct 692 ms 3264 KB Output is correct
4 Correct 252 ms 12468 KB Output is correct
5 Correct 193 ms 12152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1086 ms 21500 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 130 ms 504 KB Output is correct
2 Correct 675 ms 21496 KB Output is correct
3 Correct 464 ms 2352 KB Output is correct
4 Correct 271 ms 21480 KB Output is correct
5 Correct 253 ms 16780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1089 ms 22280 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 148 ms 496 KB Output is correct
2 Correct 731 ms 22260 KB Output is correct
3 Correct 855 ms 3432 KB Output is correct
4 Correct 315 ms 22316 KB Output is correct
5 Correct 285 ms 21528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1093 ms 23084 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 149 ms 456 KB Output is correct
2 Correct 783 ms 22928 KB Output is correct
3 Correct 745 ms 3404 KB Output is correct
4 Correct 343 ms 23060 KB Output is correct
5 Correct 288 ms 22112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1087 ms 24628 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 173 ms 568 KB Output is correct
2 Correct 920 ms 24540 KB Output is correct
3 Correct 977 ms 4596 KB Output is correct
4 Correct 427 ms 24624 KB Output is correct
5 Correct 366 ms 23340 KB Output is correct