This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ld long double
#define all(x) x.begin(), x.end()
const int N = 1e6;
const ld EPS = 1e-9;
int n;
ld h, x[N], y[N];
pair<ld, ld> sg[N];
vector<pair<ld, ld>> nwSg;
bool cmp(const pair<ld, ld>& a, const pair<ld, ld>& b) {
return a.second < b.second;
}
bool check(int i, int j, ld k) {
ld M = (h-y[i])/(k-x[i]);
ld N = h - k*M;
return x[j]*M + N < y[j];
}
signed main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n >> h;
for (int i = 0; i < n; i++) {
cin >> x[i] >> y[i];
}
vector<int> vt;
for (int i = 2; i <= n-3; i+=2) {
while (!vt.empty() && y[vt.back()] <= y[i-1]) vt.pop_back();
vt.push_back(i-1);
int sz = vt.size();
int l = 0;
int r = sz-1;
while (l < r) {
int mid = (l+r+1) >> 1;
ld m = (y[mid-1]-y[i]) / ((x[i]-x[mid-1]) - (x[i]-x[mid]));
ld p = x[i] - (h-y[i])/m;
if (check(i, vt[mid], p)) l = mid;
else r = mid-1;
}
int idx = l;
ld L = -N;
ld R = x[i];
while (R-L > EPS) {
ld mid = (L+R) / 2;
if (check(i, vt[idx], mid)) L = mid;
else R = mid;
}
sg[i].first = L;
}
vt.clear();
vt.push_back(n-2);
for (int i = n-3; i >= 2; i-=2) {
while (!vt.empty() && y[vt.back()] <= y[i+1]) vt.pop_back();
vt.push_back(i+1);
int sz = vt.size();
int l = 0;
int r = sz-1;
while (l < r) {
int mid = (l+r+1) >> 1;
ld m = (y[mid-1]-y[i]) / ((x[mid-1]-x[i]) - (x[mid]-x[i]));
ld p = x[i] + (h-y[i])/m;
if (check(i, vt[mid], p)) l = mid;
else r = mid-1;
}
int idx = l;
ld L = x[i];
ld R = N;
while (R-L > EPS) {
ld mid = (L+R) / 2;
if (check(i, vt[idx], mid)) R = mid;
else L = mid;
}
sg[i].second = L;
nwSg.push_back(sg[i]);
}
sort(all(nwSg), cmp);
int ans = 1;
int sz = nwSg.size();
ld R = nwSg[0].second;
for (int i = 1; i < sz; i++) {
if (nwSg[i].first <= R) continue;
ans++;
R = nwSg[i].second;
}
cout << ans << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |