Submission #541384

# Submission time Handle Problem Language Result Execution time Memory
541384 2022-03-23T11:43:24 Z AlperenT Planine (COCI21_planine) C++17
110 / 110
284 ms 77884 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 1e6 + 5;

struct Point{
    long long x, y;
};

int n, ans;

Point arr[N];

long double l[N], r[N], h, mx;

vector<pair<long double, long double>> v;

int orient(Point a, Point b, Point c){
    long long diff = (c.y - b.y) * (b.x - a.x) - (b.y - a.y) * (c.x - b.x);

    if(diff < 0) return 1;
    else if(diff > 0) return -1;
    else return 0;
}

vector<Point> hull;

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);

    cin >> n >> h;

    for(int i = 1; i <= n; i++) cin >> arr[i].x >> arr[i].y;

    if(n == 3){
        cout << 0;
        return 0;
    }

    hull.push_back(arr[1]), hull.push_back(arr[2]);

    for(int i = 3; i <= n - 2; i += 2){
        while(hull.size() >= 2 && orient(hull[hull.size() - 2], hull[hull.size() - 1], arr[i]) != 1) hull.pop_back();

        l[i] = arr[i].x + ((h - arr[i].y) / (hull.back().y - arr[i].y)) * (hull.back().x - arr[i].x);

        hull.push_back(arr[i]);

        while(hull.size() >= 2 && orient(hull[hull.size() - 2], hull[hull.size() - 1], arr[i + 1]) != 1) hull.pop_back();

        hull.push_back(arr[i + 1]);
    }

    hull.clear();

    hull.push_back(arr[n]), hull.push_back(arr[n - 1]);

    for(int i = n - 2; i >= 3; i -= 2){
        while(hull.size() >= 2 && orient(hull[hull.size() - 2], hull[hull.size() - 1], arr[i]) != -1) hull.pop_back();

        r[i] = arr[i].x + ((h - arr[i].y) / (hull.back().y - arr[i].y)) * (hull.back().x - arr[i].x);

        hull.push_back(arr[i]);

        while(hull.size() >= 2 && orient(hull[hull.size() - 2], hull[hull.size() - 1], arr[i - 1]) != -1) hull.pop_back();

        hull.push_back(arr[i - 1]);
    }

    for(int i = 3; i <= n - 2; i += 2) v.push_back({r[i], l[i]});

    sort(v.begin(), v.end());

    mx = v[0].first, ans = 1;

    for(int i = 1; i < v.size(); i++){
        if(v[i].second <= mx) continue;
        else ans++, mx = v[i].first;
    }

    cout << ans;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:77:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long double, long double> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |     for(int i = 1; i < v.size(); i++){
      |                    ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1112 KB Output is correct
2 Correct 3 ms 1112 KB Output is correct
3 Correct 3 ms 1112 KB Output is correct
4 Correct 21 ms 7220 KB Output is correct
5 Correct 23 ms 8384 KB Output is correct
6 Correct 25 ms 8564 KB Output is correct
7 Correct 236 ms 73920 KB Output is correct
8 Correct 237 ms 75832 KB Output is correct
9 Correct 257 ms 77688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1112 KB Output is correct
2 Correct 3 ms 1112 KB Output is correct
3 Correct 3 ms 1112 KB Output is correct
4 Correct 21 ms 7220 KB Output is correct
5 Correct 23 ms 8384 KB Output is correct
6 Correct 25 ms 8564 KB Output is correct
7 Correct 236 ms 73920 KB Output is correct
8 Correct 237 ms 75832 KB Output is correct
9 Correct 257 ms 77688 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 235 ms 74880 KB Output is correct
18 Correct 235 ms 74684 KB Output is correct
19 Correct 24 ms 8240 KB Output is correct
20 Correct 231 ms 73936 KB Output is correct
21 Correct 24 ms 8264 KB Output is correct
22 Correct 248 ms 77752 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 229 ms 76972 KB Output is correct
25 Correct 23 ms 8244 KB Output is correct
26 Correct 284 ms 77884 KB Output is correct
27 Correct 11 ms 4308 KB Output is correct