#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 7;
struct Fraction{
ll p, q;
Fraction(ll _p, ll _q){
p = _p;
q = _q;
assert(q != 0);
if (q < 0){
p = -p;
q = -q;
}
ll g = abs(__gcd(p, q));
p /= g;
q /= g;
}
bool operator == (const Fraction &oth){
return (p == oth.p && q == oth.q);
}
bool operator < (const Fraction &oth) const {
return ((long double) p * oth.q < (long double) oth.p * q);
}
};
struct Point{
int x, y;
Point(int _x = 0, int _y = 0){
x = _x;
y = _y;
}
};
struct Line{
ll a, b, c;
Line(ll _a, ll _b, ll _c){
a = _a;
b = _b;
c = _c;
}
Line(const Point &A, const Point &B){
a = A.y - B.y;
b = B.x - A.x;
c = (ll) A.x * B.y - (ll) A.y * B.x;
}
};
int n, h;
Point p[N];
Fraction findXCoor(const Line &d1, const Line &d2){
ll D = d1.a * d2.b - d2.a * d1.b;
ll Dx = -d1.c * d2.b + d2.c * d1.b;
assert(D != 0);
return Fraction(Dx, D);
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> h;
for(int i = 1; i <= n; i++)
cin >> p[i].x >> p[i].y;
Line d(0, 1, -h);
vector<pair<Fraction, Fraction>> segments;
for(int i = 3; i <= n - 2; i += 2)
segments.push_back({findXCoor(Line(p[i - 1], p[i]), d), findXCoor(Line(p[i], p[i + 1]), d)});
sort(segments.begin(), segments.end(), [](const pair<Fraction, Fraction> &a, const pair<Fraction, Fraction> &b){
return a.second < b.second;
});
int answer = 0;
Fraction lastX = Fraction(-1e18, 1);
for(auto p : segments)
if (lastX < p.first){
answer++;
lastX = p.second;
}
cout << answer;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
8556 KB |
Output is correct |
2 |
Correct |
9 ms |
8556 KB |
Output is correct |
3 |
Correct |
9 ms |
8556 KB |
Output is correct |
4 |
Correct |
30 ms |
10344 KB |
Output is correct |
5 |
Correct |
35 ms |
10492 KB |
Output is correct |
6 |
Correct |
39 ms |
10344 KB |
Output is correct |
7 |
Correct |
257 ms |
24668 KB |
Output is correct |
8 |
Correct |
308 ms |
24848 KB |
Output is correct |
9 |
Correct |
348 ms |
24784 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
8172 KB |
Output is correct |
2 |
Incorrect |
6 ms |
8172 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
8556 KB |
Output is correct |
2 |
Correct |
9 ms |
8556 KB |
Output is correct |
3 |
Correct |
9 ms |
8556 KB |
Output is correct |
4 |
Correct |
30 ms |
10344 KB |
Output is correct |
5 |
Correct |
35 ms |
10492 KB |
Output is correct |
6 |
Correct |
39 ms |
10344 KB |
Output is correct |
7 |
Correct |
257 ms |
24668 KB |
Output is correct |
8 |
Correct |
308 ms |
24848 KB |
Output is correct |
9 |
Correct |
348 ms |
24784 KB |
Output is correct |
10 |
Correct |
6 ms |
8172 KB |
Output is correct |
11 |
Incorrect |
6 ms |
8172 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |