답안 #950075

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
950075 2024-03-20T04:58:24 Z vjudge1 Planine (COCI21_planine) C++17
0 / 110
16 ms 4964 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;
}

struct frac{
    int a, b;

    frac(int a = 0, int b = 1) : a(a), b(b) {}

    bool operator <=(const frac &t){
        return a * t.b <= b * t.a;
    }

    bool operator <(const frac &t){
        return a * t.b < b * t.a;
    }

    bool operator >(const frac &t){
        return a * t.b > b * t.a;
    }
};

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;
    };
    const int inf = 1e18;
    vector <frac> 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();
            int 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 ? frac(-inf, 1) : frac(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();
            int 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 ? frac(inf, 1) : frac(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;
    frac lst = {-inf, 1};
    for ( auto &i: p ){
        if ( L[i] <= lst ){
            chmin(lst, R[i]);
        } else{
            ans++;
            lst = R[i];
        }
    }
    cout << ans;

    cout << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 860 KB Output is correct
2 Correct 3 ms 860 KB Output is correct
3 Correct 2 ms 860 KB Output is correct
4 Incorrect 16 ms 4964 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 1 ms 348 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 860 KB Output is correct
2 Correct 3 ms 860 KB Output is correct
3 Correct 2 ms 860 KB Output is correct
4 Incorrect 16 ms 4964 KB Output isn't correct
5 Halted 0 ms 0 KB -