답안 #370948

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
370948 2021-02-25T07:40:16 Z neki Planine (COCI21_planine) C++14
30 / 110
7 ms 1224 KB
#include <bits/stdc++.h>
#define ll long long
#define loop(i, a, b) for(ll i=a;i<b;i++)
#define pool(i, a, b) for(ll i=a-1;i>=b;i--)
#define fore(i, a) for(auto&& i:a)
#define fi first
#define se second
#define ps(a) push_back(a)
#define pb(a) pop_back(a)
#define sc scanf
#define vc vector
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(), a.end()
#define llmax LLONG_MAX/2
#define llmin -LLONG_MAX/2
using namespace std;
#define mn 500100
#define par pair<ll, ll>
#define ld long double
#define mod 1000000007
 
ld eps=0;
 
ll vecpro(par s, par p1, par p2){
    p1.fi-=s.fi;
    p2.fi-=s.fi;
    p1.se-=s.se;
    p2.se-=s.se;
    return p1.fi * p2.se - p2.fi * p1.se;
}
 
ld inter(par p1, par p2, ll h){
    ld k=((ld)(p2.se - p1.se)) / (p2.fi - p1.fi);
    return ((ld)(h-p1.se + k * p1.fi))/k;
}
 
vc<ld> gt(vc<par> a, ll h ){
    ll n=a.size();
    vc<par> st; 
    vc<ld> ret;
    
    for(ll i=1;i<n;i+=2){
        while(st.size()>=2 and vecpro(st[st.size()-1],  st[st.size()-2], a[i-1])<=0) st.pop_back();
        st.ps(a[i-1]);
        while(st.size()>=2 and vecpro(st[st.size()-1],  st[st.size()-2], a[i])<=0) st.pop_back();
        ret.ps(inter(st.back(), a[i], h)-eps);
        //cout << st.back().fi<<" "<<st.back().se<<" "<<a[i].fi<<" "<<a[i].se <<" "<<inter(st.back(), a[i], h)<<endl;
    }
    return ret;
}
 
int main() {
    ll n, h;cin >> n>>h;
    vc<par> poi;
    loop(i, 0, n){
        ll x, y;cin >> x >> y;
        if(i!=0 and i!=n-1)poi.ps(make_pair(x, y));
    }
    
    vc<ld> a=gt(poi, h);
    
    reverse(all(poi));
    fore(v, poi) v.fi=-v.fi;
    vc<ld> b=gt(poi, h);
    fore(v, b) v=-v;
    reverse(all(b));
    
    n=a.size();
    vc<pair<ld, ld>> ints;
    loop(i, 0, n)  ints.ps(make_pair(a[i], b[i]));
    ints.ps(make_pair(llmax, llmax));
    
    sort(all(ints));
    
    //loop(i, 0, n) cout << ints[i].fi << " "<< ints[i].se<<endl;
    
    ll cur=llmax, ans=0;
    pool(i, n, 0){
        if(ints[i].se<cur) ans++, cur=ints[i].fi;
    }
    cout << ans<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 1224 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 492 KB Output is correct
2 Correct 2 ms 492 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 2 ms 492 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 1224 KB Output isn't correct
2 Halted 0 ms 0 KB -