Submission #950078

# Submission time Handle Problem Language Result Execution time Memory
950078 2024-03-20T05:00:35 Z Alihan_8 Planine (COCI21_planine) C++17
110 / 110
224 ms 49748 KB
#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()
#define ar array
#define pb push_back
#define ln '\n'
#define int long long

using i64 = long long;

template <class F, class _S>
bool chmin(F &u, const _S &v){
    bool flag = false;
    if ( u > v ){
        u = v; flag |= true;
    }
    return flag;
}

template <class F, class _S>
bool chmax(F &u, const _S &v){
    bool flag = false;
    if ( u < v ){
        u = v; flag |= true;
    }
    return flag;
}

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

    int n, h; cin >> n >> h;
    vector <int> x(n), y(n);
    for ( int i = 0; i < n; i++ ){
        cin >> x[i] >> y[i];
    }
    auto ok = [&](int i, int j, int k, int s){
        return (x[j] - x[i]) * (y[k] - y[i]) * s >= (x[k] - x[i]) * (y[j] - y[i]) * s;
    };
    using ld = long double;
    const ld inf = 1e18, eps = 1e-8;
    vector <ld> L(n / 2 - 1), R(n / 2 - 1);
    deque <int> dq;
    dq.pb(0);
    for ( int i = 1; i + 1 < n; i++ ){
        while ( dq.size() > 1 && ok(dq[(int)dq.size() - 2], dq.back(), i, 1) ){
            dq.pop_back();
        }
        if ( i % 2 == 0 ){
            int j = dq.back();
            ld a = y[j] - y[i], b = x[j] - x[i], p = (h - y[i]) * b + a * x[i], q = a;
            L[i / 2 - 1] = !q ? -inf : p / q;
        } dq.pb(i);
    }
    dq.clear();
    dq.pb(n - 1);
    for ( int i = n - 2; i > 0; i-- ){
        while ( dq.size() > 1 && ok(dq[1], dq[0], i, -1) ){
            dq.pop_front();
        }
        if ( i % 2 == 0 ){
            int j = dq.front();
            ld a = y[j] - y[i], b = x[j] - x[i], p = (h - y[i]) * b + a * x[i], q = a;
            R[i / 2 - 1] = !q ? inf : p / q;
        } dq.push_front(i);
    }
    int m = L.size();
    vector <int> p(m);
    iota(all(p), 0);
    sort(all(p), [&](int &u, int &v){
        return L[u] <= L[v];
    });
    int ans = 0;
    ld lst = -inf;
    for ( auto &i: p ){
        if ( L[i] <= lst + eps ){
            if ( R[i] <= lst + eps ){
                lst = R[i];
            }
        } else{
            ans++;
            lst = R[i];
        }
    }
    cout << ans;

    cout << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 600 KB Output is correct
2 Correct 3 ms 604 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 17 ms 3832 KB Output is correct
5 Correct 18 ms 5036 KB Output is correct
6 Correct 20 ms 5212 KB Output is correct
7 Correct 181 ms 45672 KB Output is correct
8 Correct 184 ms 47700 KB Output is correct
9 Correct 192 ms 49492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 600 KB Output is correct
2 Correct 3 ms 604 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 17 ms 3832 KB Output is correct
5 Correct 18 ms 5036 KB Output is correct
6 Correct 20 ms 5212 KB Output is correct
7 Correct 181 ms 45672 KB Output is correct
8 Correct 184 ms 47700 KB Output is correct
9 Correct 192 ms 49492 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 196 ms 46672 KB Output is correct
18 Correct 177 ms 46444 KB Output is correct
19 Correct 19 ms 5052 KB Output is correct
20 Correct 190 ms 45908 KB Output is correct
21 Correct 19 ms 5092 KB Output is correct
22 Correct 185 ms 49388 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 182 ms 48616 KB Output is correct
25 Correct 18 ms 4944 KB Output is correct
26 Correct 224 ms 49748 KB Output is correct
27 Correct 9 ms 2648 KB Output is correct