Submission #1098012

# Submission time Handle Problem Language Result Execution time Memory
1098012 2024-10-08T19:44:19 Z 0x34c Mobile (BOI12_mobile) C++17
95 / 100
550 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)
{
    return sqrt((((ld)a.first) - x) * (((ld)a.first) - x) + (ld)(a.second * a.second));
}

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:90:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'long unsigned int' [-Wsign-compare]
   90 |     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 1 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 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 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 600 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
# Verdict Execution time Memory Grader output
1 Correct 2 ms 860 KB Output is correct
2 Correct 2 ms 1112 KB Output is correct
3 Correct 1 ms 600 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 3 ms 1112 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 8648 KB Output is correct
2 Correct 32 ms 7372 KB Output is correct
3 Correct 22 ms 6356 KB Output is correct
4 Correct 40 ms 9480 KB Output is correct
5 Correct 7 ms 1624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 2908 KB Output is correct
2 Correct 28 ms 5588 KB Output is correct
3 Correct 37 ms 9164 KB Output is correct
4 Correct 39 ms 9936 KB Output is correct
5 Correct 41 ms 10704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 15040 KB Output is correct
2 Correct 33 ms 7112 KB Output is correct
3 Correct 37 ms 13516 KB Output is correct
4 Correct 47 ms 12312 KB Output is correct
5 Correct 29 ms 4308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 7368 KB Output is correct
2 Correct 40 ms 7152 KB Output is correct
3 Correct 35 ms 4700 KB Output is correct
4 Correct 51 ms 12268 KB Output is correct
5 Correct 44 ms 10440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 14016 KB Output is correct
2 Correct 40 ms 7208 KB Output is correct
3 Correct 33 ms 4948 KB Output is correct
4 Correct 49 ms 12232 KB Output is correct
5 Correct 42 ms 10688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 236 ms 74664 KB Output is correct
2 Correct 163 ms 16772 KB Output is correct
3 Correct 156 ms 16208 KB Output is correct
4 Correct 292 ms 57444 KB Output is correct
5 Correct 269 ms 43564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 167 ms 17232 KB Output is correct
2 Correct 249 ms 56236 KB Output is correct
3 Correct 230 ms 27340 KB Output is correct
4 Correct 265 ms 57008 KB Output is correct
5 Correct 265 ms 52164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 313 ms 104100 KB Output is correct
2 Correct 175 ms 19792 KB Output is correct
3 Correct 172 ms 19020 KB Output is correct
4 Correct 319 ms 75712 KB Output is correct
5 Correct 282 ms 45244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 177 ms 20264 KB Output is correct
2 Correct 294 ms 71356 KB Output is correct
3 Correct 255 ms 26820 KB Output is correct
4 Correct 349 ms 75456 KB Output is correct
5 Correct 328 ms 68192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 377 ms 117472 KB Output is correct
2 Correct 215 ms 22652 KB Output is correct
3 Correct 208 ms 22096 KB Output is correct
4 Correct 383 ms 85200 KB Output is correct
5 Correct 345 ms 45252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 208 ms 23380 KB Output is correct
2 Correct 350 ms 80316 KB Output is correct
3 Correct 313 ms 36360 KB Output is correct
4 Correct 371 ms 84928 KB Output is correct
5 Correct 368 ms 75456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 414 ms 130980 KB Output is correct
2 Correct 228 ms 25720 KB Output is correct
3 Correct 218 ms 24916 KB Output is correct
4 Correct 462 ms 95012 KB Output is correct
5 Correct 428 ms 63684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 235 ms 26820 KB Output is correct
2 Correct 435 ms 89272 KB Output is correct
3 Correct 388 ms 38596 KB Output is correct
4 Correct 425 ms 94848 KB Output is correct
5 Correct 408 ms 83032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 438 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 257 ms 32848 KB Output is correct
2 Correct 531 ms 111004 KB Output is correct
3 Correct 482 ms 51644 KB Output is correct
4 Correct 550 ms 114120 KB Output is correct
5 Correct 538 ms 99812 KB Output is correct