This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define FOR(ii,aa,bb) for(int ii=aa;ii<bb;ii++)
#define for0(ii,bb) FOR(ii,0,bb)
#define for1(ii,bb) FOR(ii,1,bb+1)
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define st first
#define nd second
#define pii pair<int,int>
#define piii pair<int,pii>
#define piiii pair<pii,pii>
#define pdi pair<double,int>
#define vi vector<int>
#define sp " "
#define nl "\n"
#define all(x) x.begin(),x.end()
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);
#define ll long long
#define int ll
using namespace std;
const int N = 1e5+5;
const int INF = 1e9+5;
const int mod = 998244353;
int n,h;
vector<pii> p;
bool ccw(pii x,pii y,pii z){
return x.st*(y.nd-z.nd)+y.st*(z.nd-x.nd)+z.st*(x.nd-y.nd)>0;
}
bool cw(pii x,pii y,pii z){
return x.st*(y.nd-z.nd)+y.st*(z.nd-x.nd)+z.st*(x.nd-y.nd)<0;
}
bool smaller(pii x,pii y){
return x.st*y.nd<x.nd*y.st;
}
vector<pii> compute1(){
vector<pii> hull;
vector<pii> v;
for(int i=2;i<n;i++){
while(hull.size()>=2&&ccw(hull[(int)hull.size()-2],hull[(int)hull.size()-1],p[i]))
hull.pop_back();
hull.pb(p[i]);
if(i&1){
pii a=hull[(int)hull.size()-1];
pii b=hull[(int)hull.size()-2];
// cout << a.st << sp << a.nd << sp << b.st << sp << b.nd << sp;
pii c={(a.st-b.st)*(h-b.nd)+b.st*(a.nd-b.nd),a.nd-b.nd};
// cout << c.st << sp << c.nd << nl;
v.pb(c);
}
}
return v;
}
vector<pii> compute2(){
vector<pii> hull;
vector<pii> v;
for(int i=2;i<n;i++){
while(hull.size()>=2&&cw(hull[(int)hull.size()-2],hull[(int)hull.size()-1],p[i]))
hull.pop_back();
hull.pb(p[i]);
if(i&1){
pii a=hull[(int)hull.size()-1];
pii b=hull[(int)hull.size()-2];
// cout << a.st << sp << a.nd << sp << b.st << sp << b.nd << sp;
pii c={(a.st-b.st)*(h-b.nd)+b.st*(a.nd-b.nd),a.nd-b.nd};
// cout << c.st << sp << c.nd << nl;
v.pb(c);
}
}
return v;
}
signed main(){
fastio()
cin >> n >> h;
p.resize(n+2);
for(int i=1;i<=n;i++)
cin >> p[i].st >> p[i].nd;
vector<pii> a=compute1();
reverse(all(p));
vector<pii> b=compute2();
reverse(all(b));
vector<piiii> v;
for(int i=0;i<(int)a.size();i++){
v.pb({a[i],b[i]});
}
sort(all(v),[](piiii x,piiii y){
return smaller(x.nd,y.nd);
});
pii last=v[0].nd;
int ans=1;
for(int i=1;i<(int)v.size();i++){
if(smaller(last,v[i].st)){
ans++;
last=v[i].nd;
}
}
cout << ans << nl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |