#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 |
1 |
Correct |
3 ms |
1108 KB |
Output is correct |
2 |
Correct |
4 ms |
1236 KB |
Output is correct |
3 |
Correct |
4 ms |
1236 KB |
Output is correct |
4 |
Correct |
26 ms |
8104 KB |
Output is correct |
5 |
Correct |
27 ms |
8368 KB |
Output is correct |
6 |
Correct |
31 ms |
8484 KB |
Output is correct |
7 |
Correct |
262 ms |
66800 KB |
Output is correct |
8 |
Correct |
282 ms |
68588 KB |
Output is correct |
9 |
Correct |
284 ms |
70456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
2 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1108 KB |
Output is correct |
2 |
Correct |
4 ms |
1236 KB |
Output is correct |
3 |
Correct |
4 ms |
1236 KB |
Output is correct |
4 |
Correct |
26 ms |
8104 KB |
Output is correct |
5 |
Correct |
27 ms |
8368 KB |
Output is correct |
6 |
Correct |
31 ms |
8484 KB |
Output is correct |
7 |
Correct |
262 ms |
66800 KB |
Output is correct |
8 |
Correct |
282 ms |
68588 KB |
Output is correct |
9 |
Correct |
284 ms |
70456 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
460 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
460 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
2 ms |
460 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
263 ms |
67568 KB |
Output is correct |
18 |
Correct |
261 ms |
59004 KB |
Output is correct |
19 |
Correct |
27 ms |
6616 KB |
Output is correct |
20 |
Correct |
259 ms |
58312 KB |
Output is correct |
21 |
Correct |
29 ms |
6724 KB |
Output is correct |
22 |
Correct |
276 ms |
62016 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
270 ms |
61128 KB |
Output is correct |
25 |
Correct |
26 ms |
6748 KB |
Output is correct |
26 |
Correct |
302 ms |
62196 KB |
Output is correct |
27 |
Correct |
13 ms |
3580 KB |
Output is correct |