Submission #539231

# Submission time Handle Problem Language Result Execution time Memory
539231 2022-03-18T15:23:58 Z joelau Planine (COCI21_planine) C++14
110 / 110
304 ms 46628 KB
#include <bits/stdc++.h>
using namespace std;
 
long long N,H;
pair<long long,long long> A[1000005];
vector< pair<long double,long double> > lst;
vector<long long> v;
 
int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> N >> H;
    for (long long i = 0; i < N; ++i) cin >> A[i].first >> A[i].second;
    for (long long i = 2; i < N-1; i += 2) {
        while (v.size() >= 2 && (A[i-1].second - A[v[v.size()-2]].second) * (A[i-1].first - A[v.back()].first) <= (A[i-1].second - A[v.back()].second) * (A[i-1].first - A[v[v.size()-2]].first))
            v.pop_back();
        v.push_back(i-1);
        long long low = 0, high = v.size();
        while (high - low > 1) {
            long long mid = (low+high)/2;
            if ((A[i].second - A[v[mid-1]].second) * (A[i].first - A[v[mid]].first) <= (A[i].second - A[v[mid]].second) * (A[i].first - A[v[mid-1]].first)) high = mid;
            else low = mid;
        }
        lst.emplace_back(0,A[i].first - (long double) (A[i].first - A[v[low]].first) * (H - A[i].second) / (A[v[low]].second - A[i].second));
    }
    v.clear();
    for (long long i = N-3; i > 0; i -= 2) {
        while (v.size() >= 2 && (A[i+1].second - A[v[v.size()-2]].second) * (A[i+1].first - A[v.back()].first) >= (A[i+1].second - A[v.back()].second) * (A[i+1].first - A[v[v.size()-2]].first))
            v.pop_back();
        v.push_back(i+1);
        long long low = 0, high = v.size();
        while (high - low > 1) {
            long long mid = (low+high)/2;
            if ((A[i].second - A[v[mid-1]].second) * (A[i].first - A[v[mid]].first) >= (A[i].second - A[v[mid]].second) * (A[i].first - A[v[mid-1]].first)) high = mid;
            else low = mid;
        }
        lst[i/2-1].first = A[i].first + (long double) (A[v[low]].first - A[i].first) * (H - A[i].second) / (A[v[low]].second - A[i].second);
    }
    sort(lst.begin(),lst.end());
    long long ans = 0;
    long double n = -1e18;
    for (auto x: lst) if (n < x.second) ans++, n = x.first;
    cout << ans;
 
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 976 KB Output is correct
2 Correct 3 ms 964 KB Output is correct
3 Correct 4 ms 976 KB Output is correct
4 Correct 22 ms 5056 KB Output is correct
5 Correct 23 ms 5192 KB Output is correct
6 Correct 26 ms 5440 KB Output is correct
7 Correct 208 ms 34596 KB Output is correct
8 Correct 284 ms 34596 KB Output is correct
9 Correct 236 ms 34524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 976 KB Output is correct
2 Correct 3 ms 964 KB Output is correct
3 Correct 4 ms 976 KB Output is correct
4 Correct 22 ms 5056 KB Output is correct
5 Correct 23 ms 5192 KB Output is correct
6 Correct 26 ms 5440 KB Output is correct
7 Correct 208 ms 34596 KB Output is correct
8 Correct 284 ms 34596 KB Output is correct
9 Correct 236 ms 34524 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 238 ms 43500 KB Output is correct
18 Correct 282 ms 43344 KB Output is correct
19 Correct 27 ms 5068 KB Output is correct
20 Correct 242 ms 42548 KB Output is correct
21 Correct 28 ms 4980 KB Output is correct
22 Correct 293 ms 46340 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 271 ms 45512 KB Output is correct
25 Correct 25 ms 5080 KB Output is correct
26 Correct 304 ms 46628 KB Output is correct
27 Correct 16 ms 2728 KB Output is correct