Submission #969213

# Submission time Handle Problem Language Result Execution time Memory
969213 2024-04-24T16:55:05 Z d4xn Planine (COCI21_planine) C++17
0 / 110
8 ms 7260 KB
#include <bits/stdc++.h>
using namespace std;

#define ld long double
#define all(x) x.begin(), x.end()

const int N = 1e6;

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 (L < R) {
      ld mid = (L+R) / 2;
      
      if (check(i, vt[idx], mid)) L = mid+1;
      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 (L < R) {
      ld mid = (L+R+1) / 2;
      
      if (check(i, vt[idx], mid)) R = mid-1;
      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 time Memory Grader output
1 Incorrect 8 ms 7260 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4700 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 7260 KB Output isn't correct
2 Halted 0 ms 0 KB -