#include <bits/stdc++.h>
typedef long double ld;
typedef long long ll;
using namespace std;
int nums; ll h;
struct pt{
ll x, y;
};
struct hull{
vector<pt> v;
bool ccw(pt a, pt b, pt c){
return a.x * (b.y - c.y) + b.x * (c.y - a.y) + c.x * (a.y - b.y) > 0;
}
void insert(pt p){
while (v.size() >= 2 && ccw(v[v.size() - 2], v.back(), p)) v.pop_back();
v.push_back(p);
}
pair<ll, ll> query(pt p){
insert(p);
auto [x0, y0] = v.rbegin()[0];
auto [x1, y1] = v.rbegin()[1];
return {(x0 - x1) * (h - y1) + x1 * (y0 - y1), y0 - y1};
}
};
bool cmpfrac(pair<ll, ll> a, pair<ll, ll> b){
return a.first * b.second < b.first * a.second;
}
bool cmp(pair<pair<ll ,ll>, pair<ll, ll>> a, pair<pair<ll ,ll>, pair<ll, ll>> b){
return cmpfrac(a.second, b.second);
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> nums >> h;
pt vec[nums];
for (int i = 0; i < nums; i++) cin >> vec[i].x >> vec[i].y;
int valley = (nums - 3) / 2;
pair<pair<ll, ll>, pair<ll, ll>> range[valley];
hull left;
for (int i = 1, j = 0; i < nums - 1; i++){
if (i % 2) left.insert(vec[i]);
else {
range[j].first = left.query(vec[i]);
j++;
}
}
hull right;
for (int i = nums - 2, j = valley - 1; i >= 1; i--){
if (i % 2) right.insert(vec[i]);
else {
range[j].second = right.query(vec[i]);
j--;
}
}
sort(range, range + valley, cmp);
int ans = 0; pair<ll, ll> last_pos;
for (int i = 0; i < valley; i++)
if (i == 0 || cmpfrac(last_pos, range[i].first)){
ans++;
last_pos = range[i].second;
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
724 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
724 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |