#include <bits/stdc++.h>
typedef long double ld;
typedef long long ll;
using namespace std;
int nums; ld h;
const ld error = 1e-18;
struct pt{
ld x, y;
};
struct hull{
vector<pt> v;
ld intersect(pt a, pt b){
return (h - b.y) / (a.y - b.y) * (a.x - b.x) + b.x;
}
void insert(pt p){
while (!v.empty() && v.back().y <= p.y) v.pop_back();
v.push_back(p);
}
ld query(pt p){
while (v.size() >= 2 && abs(intersect(p, v.back()) - p.x) >= abs(intersect(p, v[v.size() - 2]) - p.x)) v.pop_back();
return intersect(p, v.back());
}
};
bool cmp(pair<ld, ld> a, pair<ld, ld> b){
return 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<ld, ld> 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; ld last_pos = -1e18;
for (int i = 0; i < valley; i++)
if ((ll)(range[i].first * 1e6) > (ll)(last_pos * 1e6)){
ans++;
last_pos = range[i].second;
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
852 KB |
Output is correct |
2 |
Correct |
6 ms |
848 KB |
Output is correct |
3 |
Correct |
7 ms |
856 KB |
Output is correct |
4 |
Correct |
55 ms |
5576 KB |
Output is correct |
5 |
Correct |
74 ms |
5580 KB |
Output is correct |
6 |
Correct |
66 ms |
5576 KB |
Output is correct |
7 |
Correct |
617 ms |
48564 KB |
Output is correct |
8 |
Correct |
632 ms |
48532 KB |
Output is correct |
9 |
Correct |
687 ms |
48468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
400 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
3 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
852 KB |
Output is correct |
2 |
Correct |
6 ms |
848 KB |
Output is correct |
3 |
Correct |
7 ms |
856 KB |
Output is correct |
4 |
Correct |
55 ms |
5576 KB |
Output is correct |
5 |
Correct |
74 ms |
5580 KB |
Output is correct |
6 |
Correct |
66 ms |
5576 KB |
Output is correct |
7 |
Correct |
617 ms |
48564 KB |
Output is correct |
8 |
Correct |
632 ms |
48532 KB |
Output is correct |
9 |
Correct |
687 ms |
48468 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
400 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
3 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
2 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
597 ms |
56328 KB |
Output is correct |
18 |
Incorrect |
620 ms |
56312 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |