답안 #1088606

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1088606 2024-09-14T16:35:26 Z DaciejMaciej Mobile (BOI12_mobile) C++17
100 / 100
382 ms 41676 KB
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/rope>

using namespace std;
// using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef long double ld;

template <class T>

using VV = vector<vector<T>>;

using VI = vector<int>;
using VVI = vector<vector<int>>;

using VL = vector<long long>;
using VVL = vector<vector<long long>>;

using VC = vector<char>;
using VVC = vector<vector<char>>;

using VB = vector<bool>;
using VVB = vector<vector<bool>>;

using VD = vector<double>;
using VVD = vector<vector<double>>;

using PII = pair<int, int>;
using PLL = pair<long long, long long>;
using PIL = pair<int, long long>;
using PLI = pair<long long, int>;

using VPII = vector<pair<int, int>>;
using VPLL = vector<pair<long long, long long>>;

#define LINE '\n'
#define SPACE ' '
#define PB push_back
#define FOR(i, a, b) for (int i = (a); i < (int(b)); i++)
#define FORE(i, a, b) for (int i = (a); i <= (int)((b)); i++)
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
#define sq(a) ((a) * (a))
#define sz(x) ((int)x.size())


#define debug(x) cerr << #x << " = " << x << endl;


// zero indexed
template <class T>
struct segtree
{
    const T def = 0;
    int n;
    vector<T> seg;

    segtree(int _size) : n(_size), seg(2 * _size, def) {}

    T merge(T a, T b)
    {
        return max(a, b);
    }
    void update(int pos, T val)
    {
        for (seg[pos += n] = val; pos /= 2;)
        {
            seg[pos] = merge(seg[pos * 2], seg[pos * 2 + 1]);
        }
    }
    T query(int l, int r)
    { // get [l, r]
        T a = def, b = def;
        for (l += n, r += n + 1; l < r; l /= 2, r /= 2)
        {
            if (l % 2)
                a = merge(a, seg[l++]);
            if (r % 2)
                b = merge(b, seg[--r]);
        }
        return merge(a, b);
    }
};

const ll MOD = 1e9 + 7;

template <class T>
void maxi(T &a, T b)
{
    a = max(a, b);
}

template <class T>
void mini(T &a, T b)
{
    a = min(a, b);
}

template <class T>
void addi(T &a, T b)
{
    a = (a + b) % MOD;
}

template <class T>
void subi(T &a, T b)
{
    a = (a - b + MOD) % MOD;
}

template <class T>
T add(T a, T b)
{
    return (a + b) % MOD;
}

template <class T>
T sub(T a, T b)
{
    return (a - b + MOD) % MOD;
}

template <class T>
T mul(T a, T b)
{
    return ((a % MOD) * (b % MOD)) % MOD;
}

ll binpow(ll a, ll b, ll mod)
{
    ll res = 1;
    while (b > 0)
    {
        if (b & 1)
        {
            res = (res * a) % mod;
        }
        a = (a * a) % mod;
        b >>= 1;
    }

    return res;
}

const int INF = 1e9;

const int MAX_N = 1e5 + 3;

using LD = long double;
struct P {
    LD x = 0;
    LD y = 0;
};

LD mp(const P &a, const P &b) {
    return (sq(b.x) + sq(b.y) - sq(a.x) - sq(a.y)) / (2 * (b.x-a.x));
}

LD dist(const P &a, const P &b) {
    return sqrt(sq(a.x-b.x) + sq(a.y-b.y));
}

void solve()
{
    int n, l;
    cin >> n >> l;

    deque<P> dq;
    FOR(i, 0, n) {
        P c;
        cin >> c.x >> c.y;
        c.y = abs(c.y);
        
        if(sz(dq) && dq.back().x == c.x)  {
            if(c.y >= dq.back().y) continue;
            else {
                dq.pop_back();
            }
        }

        while(sz(dq) >= 2  &&
            mp(dq[sz(dq)-2], dq.back()) > mp(dq.back(), c)) {
                dq.pop_back();
        }

        dq.push_back(c);
    }

    
    while(sz(dq) > 1 && mp(dq[0], dq[1]) < 0) dq.pop_front();
    while(sz(dq) > 1 && mp(dq[sz(dq)-2], dq.back()) > l) dq.pop_back();

    LD ans = 0;
    FOR(i, 0, sz(dq)) {
        P left, right;
        right.x = l;

        if(i) {
            left.x = mp(dq[i], dq[i-1]);
        }
        if(i < sz(dq) - 1) {
            right.x = mp(dq[i], dq[i+1]);
        }
        
        if(left.x < 0 || right.x > l || right.x < 0 || right.x > l) continue;

        ans = max({ans, dist(dq[i], left), dist(dq[i], right)});
    }
    
    cout << fixed << setprecision(6) << ans << LINE;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
    // cin >> t;

    while (t--)
        solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 1 ms 464 KB Output is correct
4 Correct 2 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 524 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 3 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 2 ms 544 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 1368 KB Output is correct
2 Correct 23 ms 1496 KB Output is correct
3 Correct 15 ms 1116 KB Output is correct
4 Correct 27 ms 1628 KB Output is correct
5 Correct 15 ms 856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 1116 KB Output is correct
2 Correct 21 ms 1256 KB Output is correct
3 Correct 26 ms 1372 KB Output is correct
4 Correct 27 ms 1628 KB Output is correct
5 Correct 30 ms 1880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 3788 KB Output is correct
2 Correct 24 ms 1480 KB Output is correct
3 Correct 25 ms 3668 KB Output is correct
4 Correct 43 ms 2640 KB Output is correct
5 Correct 25 ms 1364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 1884 KB Output is correct
2 Correct 34 ms 1624 KB Output is correct
3 Correct 26 ms 1876 KB Output is correct
4 Correct 39 ms 2232 KB Output is correct
5 Correct 36 ms 1616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 3848 KB Output is correct
2 Correct 31 ms 1732 KB Output is correct
3 Correct 25 ms 1744 KB Output is correct
4 Correct 50 ms 2392 KB Output is correct
5 Correct 32 ms 1624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 150 ms 21212 KB Output is correct
2 Correct 155 ms 8020 KB Output is correct
3 Correct 135 ms 7612 KB Output is correct
4 Correct 181 ms 9924 KB Output is correct
5 Correct 160 ms 7248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 144 ms 8528 KB Output is correct
2 Correct 164 ms 8788 KB Output is correct
3 Correct 136 ms 9332 KB Output is correct
4 Correct 185 ms 9816 KB Output is correct
5 Correct 162 ms 7748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 229 ms 25092 KB Output is correct
2 Correct 167 ms 9552 KB Output is correct
3 Correct 183 ms 9040 KB Output is correct
4 Correct 220 ms 12624 KB Output is correct
5 Correct 188 ms 8392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 163 ms 10284 KB Output is correct
2 Correct 190 ms 10060 KB Output is correct
3 Correct 151 ms 9560 KB Output is correct
4 Correct 225 ms 12080 KB Output is correct
5 Correct 200 ms 9016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 218 ms 29444 KB Output is correct
2 Correct 216 ms 11092 KB Output is correct
3 Correct 205 ms 10548 KB Output is correct
4 Correct 256 ms 14016 KB Output is correct
5 Correct 209 ms 9300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 207 ms 11820 KB Output is correct
2 Correct 226 ms 11604 KB Output is correct
3 Correct 186 ms 12896 KB Output is correct
4 Correct 257 ms 13652 KB Output is correct
5 Correct 227 ms 10568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 240 ms 33540 KB Output is correct
2 Correct 222 ms 12724 KB Output is correct
3 Correct 241 ms 11864 KB Output is correct
4 Correct 304 ms 15932 KB Output is correct
5 Correct 261 ms 11580 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 220 ms 13396 KB Output is correct
2 Correct 261 ms 13036 KB Output is correct
3 Correct 233 ms 13764 KB Output is correct
4 Correct 293 ms 15952 KB Output is correct
5 Correct 262 ms 11848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 309 ms 41676 KB Output is correct
2 Correct 277 ms 15952 KB Output is correct
3 Correct 263 ms 14908 KB Output is correct
4 Correct 372 ms 19632 KB Output is correct
5 Correct 308 ms 13876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 293 ms 16936 KB Output is correct
2 Correct 322 ms 15696 KB Output is correct
3 Correct 267 ms 17748 KB Output is correct
4 Correct 382 ms 19636 KB Output is correct
5 Correct 328 ms 15160 KB Output is correct