이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "trilib.h"
using namespace std;
#define rep(i, a, b) for (auto i = (a); i <= (b); ++i)
#define all(x...) begin(x), end(x)
const int N = 1 << 17;
bool halfplane[N];
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n = get_n();
vector<int> upper, lower;
halfplane[1] = 0;
rep(i, 3, n) {
halfplane[i] = is_clockwise(1, 2, i);
(halfplane[i] ? lower : upper).push_back(i);
}
sort(all(upper), [](int x, int y) -> bool {
if (x == y) return false;
return !is_clockwise(2, x, y);
});
vector<int> upper_hull = {2}; int t = 1;
for (int i : upper) {
while (t > 1 && is_clockwise(upper_hull[t - 2], upper_hull[t - 1], i)) upper_hull.pop_back(), --t;
upper_hull.push_back(i); ++t;
}
sort(all(lower), [](int x, int y) -> bool {
if (x == y) return false;
return !is_clockwise(1, x, y);
});
vector<int> lower_hull = {1}; t = 1;
for (int i : lower) {
while (t > 1 && is_clockwise(lower_hull[t - 2], lower_hull[t - 1], i)) lower_hull.pop_back(), --t;
lower_hull.push_back(i); ++t;
}
vector<int> hull = upper_hull; t = hull.size();
for (int i : lower_hull) {
while (t > 1 && is_clockwise(hull[t - 2], hull[t - 1], i)) hull.pop_back(), --t;
hull.push_back(i); ++t;
}
auto it = begin(hull);
for ( ; it != end(hull); ++it) if (halfplane[*it]) break;
upper_hull = {begin(hull), it};
hull.erase(begin(hull), it);
t = hull.size();
for (int i : upper_hull) {
if (t > 1 && halfplane[hull[t - 2]])
while (t > 1 && is_clockwise(hull[t - 2], hull[t - 1], i)) hull.pop_back(), --t;
hull.push_back(i); ++t;
}
give_answer(hull.size());
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |