Submission #1098019

# Submission time Handle Problem Language Result Execution time Memory
1098019 2024-10-08T19:52:35 Z 0x34c Mobile (BOI12_mobile) C++17
95 / 100
579 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;

        if (x1 - x2 == 0)
            return (ld)-1;
        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:93:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'long unsigned int' [-Wsign-compare]
   93 |     for (int i = 0; i < (bps.empty() ? 0 : bps.size()); i++)
      |                     ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 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 0 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 860 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 604 KB Output is correct
2 Correct 2 ms 860 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 2 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 2 ms 860 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 3 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1044 KB Output is correct
2 Correct 2 ms 860 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 2 ms 860 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 7876 KB Output is correct
2 Correct 32 ms 6260 KB Output is correct
3 Correct 20 ms 5584 KB Output is correct
4 Correct 34 ms 8400 KB Output is correct
5 Correct 7 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 2064 KB Output is correct
2 Correct 38 ms 4812 KB Output is correct
3 Correct 34 ms 8144 KB Output is correct
4 Correct 48 ms 8656 KB Output is correct
5 Correct 56 ms 9168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 14336 KB Output is correct
2 Correct 33 ms 6088 KB Output is correct
3 Correct 37 ms 12668 KB Output is correct
4 Correct 52 ms 10360 KB Output is correct
5 Correct 29 ms 3548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 5760 KB Output is correct
2 Correct 40 ms 5748 KB Output is correct
3 Correct 41 ms 3664 KB Output is correct
4 Correct 66 ms 10216 KB Output is correct
5 Correct 45 ms 9156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 12484 KB Output is correct
2 Correct 41 ms 5832 KB Output is correct
3 Correct 37 ms 3664 KB Output is correct
4 Correct 53 ms 10308 KB Output is correct
5 Correct 45 ms 9240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 246 ms 70316 KB Output is correct
2 Correct 189 ms 9040 KB Output is correct
3 Correct 189 ms 9044 KB Output is correct
4 Correct 260 ms 47672 KB Output is correct
5 Correct 257 ms 36796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 159 ms 9040 KB Output is correct
2 Correct 253 ms 49588 KB Output is correct
3 Correct 231 ms 21452 KB Output is correct
4 Correct 272 ms 47804 KB Output is correct
5 Correct 256 ms 44992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 312 ms 99016 KB Output is correct
2 Correct 178 ms 10324 KB Output is correct
3 Correct 187 ms 10412 KB Output is correct
4 Correct 335 ms 63936 KB Output is correct
5 Correct 312 ms 37056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 174 ms 10324 KB Output is correct
2 Correct 301 ms 63500 KB Output is correct
3 Correct 245 ms 19752 KB Output is correct
4 Correct 323 ms 63932 KB Output is correct
5 Correct 305 ms 59300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 364 ms 111512 KB Output is correct
2 Correct 223 ms 11852 KB Output is correct
3 Correct 193 ms 11864 KB Output is correct
4 Correct 402 ms 71692 KB Output is correct
5 Correct 351 ms 36288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 207 ms 11792 KB Output is correct
2 Correct 373 ms 71104 KB Output is correct
3 Correct 320 ms 28108 KB Output is correct
4 Correct 384 ms 71620 KB Output is correct
5 Correct 394 ms 65216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 444 ms 123988 KB Output is correct
2 Correct 229 ms 13396 KB Output is correct
3 Correct 210 ms 13480 KB Output is correct
4 Correct 469 ms 79544 KB Output is correct
5 Correct 413 ms 52680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 215 ms 13396 KB Output is correct
2 Correct 412 ms 78780 KB Output is correct
3 Correct 356 ms 29124 KB Output is correct
4 Correct 433 ms 79548 KB Output is correct
5 Correct 419 ms 71524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 437 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 273 ms 16720 KB Output is correct
2 Correct 523 ms 97692 KB Output is correct
3 Correct 484 ms 39220 KB Output is correct
4 Correct 579 ms 95168 KB Output is correct
5 Correct 548 ms 85056 KB Output is correct