이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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();
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;
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'int main()':
Main.cpp:33:162: warning: statement has no effect [-Wunused-value]
33 | 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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |