Submission #386509

#TimeUsernameProblemLanguageResultExecution timeMemory
386509phathnvPlanine (COCI21_planine)C++11
20 / 110
324 ms48444 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1e6 + 7; 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]; long double 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 (long double) 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<long double, long double>> segments; for(int i = 3; i <= n - 2; i += 2){ //cerr << findXCoor(Line(p[i - 1], p[i]), d) << ' ' << findXCoor(Line(p[i], p[i + 1]), d) << endl; 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<long double, long double> &a, const pair<long double, long double> &b){ if (a.second != b.second) return a.second < b.second; return a.first > b.first; }); long double lastX = -1e18; vector<pair<long double, long double>> nxt; for(auto p : segments) if (lastX < p.first){ lastX = p.first; nxt.push_back(p); } sort(nxt.begin(), nxt.end()); lastX = -1e18; int answer = 0; for(auto p : nxt) if (lastX < p.first){ answer++; lastX = p.second; } cout << answer; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...