Submission #1096189

# Submission time Handle Problem Language Result Execution time Memory
1096189 2024-10-04T04:40:42 Z Omar_Elgedawy Mobile (BOI12_mobile) C++17
8 / 100
179 ms 64544 KB
#include <bits/stdc++.h>

using namespace std;
#define int long long
#define ld long double
#define F first
#define S second
#define el '\n'
#define cout(x) for(auto v:x)cout<<v<<el
#define coutp(x) for(auto v:x)cout<<v.F<<' '<<v.S<<el
#define cin(x) for(auto &v:x)cin>>v;
#define pb(x) push_back(x)
#define all(x)  x.begin(),x.end()

const int N = 5e3 + 5, M = 1e2 + 5, Mod = 1e9 + 7;
int dx[8] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[8] = {0, 0, 1, -1, 1, -1, -1, 1};

int nxt()
{
    int x;
    cin >> x;
    return x;
}

ld midX(pair<ld,ld> a, pair<ld,ld> b)
{
    return (b.F * b.F + b.S * b.S - a.F * a.F - a.S * a.S) / (2 * b.F - 2 * a.F);
}

ld dist(pair<ld,ld> a, pair<ld,ld> b)
{
    return sqrtl((a.F - b.F) * (a.F - b.F) + (a.S - b.S) * (a.S - b.S));
}

void solve(int h)
{
    int n, m;
    cin >> n >> m;
    vector<pair<int,int>> v;
    ld x[n], y[n];
    deque<pair<ld,ld>> st;
    for (int i = 0; i < n; i++)
    {
        int a, b;
        cin >> a >> b;
        x[i] = a;
        y[i] = abs(b);
        if (st.size() && st.back().F == x[i])
        {
            if (st.back().S <= y[i])
            {
                continue;
            }
            else
            {
                st.pop_back();
            }
        }
        while (st.size() > 1 &&
            midX(st[st.size() - 2], st.back()) >
            midX(st.back(), {x[i], y[i]}))
        {
            st.pop_back();
        }
        st.push_back({x[i], y[i]});
    }
    while (st.size() > 1 &&
        midX(st[0], st[1]) < 0)
    {
        st.pop_front();
    }
    while (st.size() > 1 &&
        midX(st.back(), st[st.size() - 2]) > m)
    {
        st.pop_back();
    }
    ld mx = 0;
    for (int i = 0; i < st.size(); i++)
    {
        pair<ld,ld> left = {0, 0}, right = {m, 0};
        if (i)left.F = midX(st[i], st[i - 1]);
        if (i != st.size() - 1)right.F = midX(st[i], st[i + 1]);
        if (left.F < 0 || left.F > m || right.F < 0 || right.F > m)
            continue;
        mx = max({mx, dist(st[i], left), dist(st[i], right)});
    }
    cout << mx;
}

int32_t main()
{
// #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
 // #endif
    // freopen("feast.in", "r", stdin);
    // freopen("feast.out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int tc = 1;
    // cin >> tc;
    for (int i = 1; i <= tc; i++)solve(i);
    return 0;
}

Compilation message

mobile.cpp: In function 'void solve(long long int)':
mobile.cpp:79:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::deque<std::pair<long double, long double> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |     for (int i = 0; i < st.size(); i++)
      |                     ~~^~~~~~~~~~~
mobile.cpp:83:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::deque<std::pair<long double, long double> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |         if (i != st.size() - 1)right.F = midX(st[i], st[i + 1]);
      |             ~~^~~~~~~~~~~~~~~~
# 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 344 KB Output is correct
# 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 1 ms 604 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Incorrect 1 ms 604 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 604 KB Output is correct
2 Incorrect 1 ms 604 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Incorrect 1 ms 604 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Incorrect 1 ms 604 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 2908 KB Output is correct
2 Incorrect 12 ms 2652 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 2904 KB Output is correct
2 Correct 14 ms 2652 KB Output is correct
3 Incorrect 15 ms 2908 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 5976 KB Output is correct
2 Incorrect 15 ms 2908 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 19 ms 3416 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 21 ms 5468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 89 ms 32352 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 76 ms 15960 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 115 ms 38868 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 82 ms 19036 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 133 ms 45160 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 101 ms 22364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 151 ms 51544 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 117 ms 25480 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 179 ms 64544 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 147 ms 31576 KB Output isn't correct
2 Halted 0 ms 0 KB -