Submission #969217

#TimeUsernameProblemLanguageResultExecution timeMemory
969217d4xnPlanine (COCI21_planine)C++17
0 / 110
14 ms7004 KiB
#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<int, int>& a, const pair<int, int>& 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)); 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...