#include <bits/stdc++.h>
typedef long double ld;
using namespace std;
int nums, h;
const ld error = 1e-9;
struct pt{
ld x, y;
};
struct hull{
vector<pt> v;
ld intersect(pt a, pt b){
ld m = (b.y - a.y) / (b.x - a.x), c = b.y - b.x * m;
return (h - c) / m;
}
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<int, int> a, pair<int, int> b){
return a.second < b.second;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> nums >> h;
vector<pt> vec(nums);
for (int i = 0; i < nums; i++) cin >> vec[i].x >> vec[i].y;
int valley = (nums - 3) / 2;
vector<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.begin(), range.end(), cmp);
int ans = 0; ld last_pos = -1e18;
for (int i = 0; i < valley; i++)
if (range[i].first > last_pos + error){
ans++;
last_pos = range[i].second;
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
852 KB |
Output is correct |
2 |
Correct |
16 ms |
724 KB |
Output is correct |
3 |
Correct |
19 ms |
788 KB |
Output is correct |
4 |
Correct |
258 ms |
5024 KB |
Output is correct |
5 |
Correct |
244 ms |
6096 KB |
Output is correct |
6 |
Correct |
191 ms |
6308 KB |
Output is correct |
7 |
Execution timed out |
2091 ms |
48340 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
340 KB |
Output is correct |
2 |
Correct |
3 ms |
428 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
5 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
5 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
852 KB |
Output is correct |
2 |
Correct |
16 ms |
724 KB |
Output is correct |
3 |
Correct |
19 ms |
788 KB |
Output is correct |
4 |
Correct |
258 ms |
5024 KB |
Output is correct |
5 |
Correct |
244 ms |
6096 KB |
Output is correct |
6 |
Correct |
191 ms |
6308 KB |
Output is correct |
7 |
Execution timed out |
2091 ms |
48340 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |