Submission #1098016

# Submission time Handle Problem Language Result Execution time Memory
1098016 2024-10-08T19:49:32 Z 0x34c Mobile (BOI12_mobile) C++17
95 / 100
560 ms 131072 KB
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define endl '\n'
#define int ll
#define ld long double
#define pdd pair<ld, ld>

using namespace std;

int dist2(pii a, pii b)
{
    return (a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second);
}

ld dist(pii a, ld x)
{
    ld x1 = a.first, y = a.second;
    return sqrt((x1 - x) * (x1 - x) + y * y);
}

const int INF2 = 1e12;
const int INF = 1e9 + 1;
ld eps = 1e-4;

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

    int N, L;
    cin >> N >> L;

    vector<pii> inp(N);
    map<int, int> closest;
    for (int i = 0; i < N; i++)
    {
        int x, y;
        cin >> x >> y;

        inp[i] = {x, y};

        if (!closest.count(x))
            closest[x] = y;
        else
            closest[x] = (abs(closest[x]) > abs(y) ? y : closest[x]);
    }

    vector<pii> pts;
    for (pii p : closest)
        pts.push_back(p);

    N = pts.size();

    auto calc_bp = [&](int idx1, int idx2)
    {
        ld x1 = pts[idx1].first, y1 = pts[idx1].second;
        ld x2 = pts[idx2].first, y2 = pts[idx2].second;

        return ((ld)0.5) * (x1 + x2 + (y1 * y1 - y2 * y2) / (x1 - x2));
    };

    stack<int> stk;
    stk.push(0);
    vector<ld> dists, bps;
    for (int i = 1; i < N; i++)
    {
        ld bp = calc_bp(stk.top(), i);
        bool emp = false;

        while (!bps.empty() && bps.back() > bp)
        {
            bps.pop_back();
            stk.pop();
            dists.pop_back();
            if (stk.empty())
                emp = true;
            else
                bp = calc_bp(stk.top(), i);
        }

        if (!emp)
        {
            bps.push_back(bp);
            dists.push_back(dist(pts[i], bp));
        }
        stk.push(i);
    }

    ld mx_dist = 0;
    for (int i = 0; i < (bps.empty() ? 0 : bps.size()); i++)
    {
        if (bps[i] < 0 || bps[i] > L)
            continue;
        mx_dist = max(mx_dist, dists[i]);
    }

    ld mn_start = INF2, mn_end = INF2;
    for (int i = 0; i < N; i++)
    {
        mn_start = min(mn_start, dist(pts[i], 0));
        mn_end = min(mn_end, dist(pts[i], L));
    }

    mx_dist = max({mx_dist, mn_start, mn_end});
    cout << setprecision(4) << fixed << mx_dist << endl;
}

Compilation message

mobile.cpp: In function 'int main()':
mobile.cpp:91:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'long unsigned int' [-Wsign-compare]
   91 |     for (int i = 0; i < (bps.empty() ? 0 : bps.size()); i++)
      |                     ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 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 0 ms 348 KB Output is correct
2 Correct 0 ms 456 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 860 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 2 ms 940 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 2 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 860 KB Output is correct
2 Correct 2 ms 940 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 2 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 856 KB Output is correct
2 Correct 2 ms 1116 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 2 ms 1116 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 8828 KB Output is correct
2 Correct 33 ms 7368 KB Output is correct
3 Correct 21 ms 6408 KB Output is correct
4 Correct 36 ms 9680 KB Output is correct
5 Correct 7 ms 1628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 2904 KB Output is correct
2 Correct 29 ms 5588 KB Output is correct
3 Correct 35 ms 9164 KB Output is correct
4 Correct 36 ms 9932 KB Output is correct
5 Correct 41 ms 10704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 15044 KB Output is correct
2 Correct 35 ms 7112 KB Output is correct
3 Correct 37 ms 13516 KB Output is correct
4 Correct 48 ms 12248 KB Output is correct
5 Correct 29 ms 4312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 7372 KB Output is correct
2 Correct 41 ms 7116 KB Output is correct
3 Correct 34 ms 4720 KB Output is correct
4 Correct 47 ms 12232 KB Output is correct
5 Correct 43 ms 10436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 14120 KB Output is correct
2 Correct 41 ms 7116 KB Output is correct
3 Correct 33 ms 4912 KB Output is correct
4 Correct 48 ms 12228 KB Output is correct
5 Correct 43 ms 10644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 239 ms 74424 KB Output is correct
2 Correct 154 ms 16120 KB Output is correct
3 Correct 154 ms 15956 KB Output is correct
4 Correct 255 ms 56764 KB Output is correct
5 Correct 238 ms 43088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 154 ms 16836 KB Output is correct
2 Correct 239 ms 55880 KB Output is correct
3 Correct 216 ms 26828 KB Output is correct
4 Correct 261 ms 56512 KB Output is correct
5 Correct 254 ms 51836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 321 ms 104100 KB Output is correct
2 Correct 180 ms 19024 KB Output is correct
3 Correct 188 ms 18260 KB Output is correct
4 Correct 353 ms 74684 KB Output is correct
5 Correct 295 ms 44480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 183 ms 19540 KB Output is correct
2 Correct 303 ms 70584 KB Output is correct
3 Correct 250 ms 26312 KB Output is correct
4 Correct 313 ms 74688 KB Output is correct
5 Correct 306 ms 66236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 350 ms 116380 KB Output is correct
2 Correct 200 ms 20384 KB Output is correct
3 Correct 199 ms 20052 KB Output is correct
4 Correct 383 ms 82112 KB Output is correct
5 Correct 340 ms 43468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 204 ms 20860 KB Output is correct
2 Correct 366 ms 78572 KB Output is correct
3 Correct 318 ms 34880 KB Output is correct
4 Correct 394 ms 82160 KB Output is correct
5 Correct 376 ms 73664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 417 ms 130724 KB Output is correct
2 Correct 220 ms 24656 KB Output is correct
3 Correct 219 ms 24096 KB Output is correct
4 Correct 433 ms 93884 KB Output is correct
5 Correct 395 ms 62796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 219 ms 25560 KB Output is correct
2 Correct 403 ms 88412 KB Output is correct
3 Correct 366 ms 38080 KB Output is correct
4 Correct 439 ms 93828 KB Output is correct
5 Correct 421 ms 82112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 448 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 271 ms 31280 KB Output is correct
2 Correct 551 ms 109840 KB Output is correct
3 Correct 483 ms 50408 KB Output is correct
4 Correct 560 ms 112576 KB Output is correct
5 Correct 514 ms 98352 KB Output is correct