Submission #539141

# Submission time Handle Problem Language Result Execution time Memory
539141 2022-03-18T13:25:10 Z joelau Planine (COCI21_planine) C++14
20 / 110
2000 ms 32552 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()-1]].first))
            v.pop_back();
        v.push_back(i-1);
        long long low = 0, high = v.size()-1;
        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;
        }
        long double d1 = A[i].first - (long double) (A[i].first - A[v[high]].first) * (H - A[i].second) / (A[v[high]].second - A[i].second);
        long double d2 = A[i].first - (long double) (A[i].first - A[v[0]].first) * (H - A[i].second) / (A[v[0]].second - A[i].second);
        lst.emplace_back(0,max(d1,d2));
    }
    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()-1;
        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;
        }
        long double d1 = A[i].first + (long double) (A[v[high]].first - A[i].first) * (H - A[i].second) / (A[v[high]].second - A[i].second);
        long double d2 = A[i].first + (long double) (A[v[0]].first - A[i].first) * (H - A[i].second) / (A[v[0]].second - A[i].second);
        lst[i/2-1].first = min(d1,d2);
    }
    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;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:35:162: warning: statement has no effect [-Wunused-value]
   35 |             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;
      |                                                                                                                                                             ~~~~~^~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 852 KB Output is correct
2 Correct 3 ms 852 KB Output is correct
3 Correct 3 ms 852 KB Output is correct
4 Correct 20 ms 4028 KB Output is correct
5 Correct 21 ms 3984 KB Output is correct
6 Correct 24 ms 4048 KB Output is correct
7 Correct 214 ms 32440 KB Output is correct
8 Correct 230 ms 32504 KB Output is correct
9 Correct 240 ms 32552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Execution timed out 2057 ms 340 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 852 KB Output is correct
2 Correct 3 ms 852 KB Output is correct
3 Correct 3 ms 852 KB Output is correct
4 Correct 20 ms 4028 KB Output is correct
5 Correct 21 ms 3984 KB Output is correct
6 Correct 24 ms 4048 KB Output is correct
7 Correct 214 ms 32440 KB Output is correct
8 Correct 230 ms 32504 KB Output is correct
9 Correct 240 ms 32552 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Execution timed out 2057 ms 340 KB Time limit exceeded
12 Halted 0 ms 0 KB -