이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "trilib.h"
#include <bits/stdc++.h>
using namespace std;
int main() {
int n = get_n();
vector<int> upper, lower;
for (int i = 3; i <= n; i++) {
if (is_clockwise(2, 1, i)) upper.push_back(i);
else lower.push_back(i);
}
sort(upper.begin(), upper.end(), [&](int a, int b) {
return is_clockwise(1, a, b);
});
vector<int> upper_hull = {1};
upper.push_back(2);
for (auto &i : upper) {
while ((int) upper_hull.size() >= 2 && is_clockwise(i, upper_hull.back(), upper_hull[(int) upper_hull.size() - 2])) upper_hull.pop_back();
upper_hull.push_back(i);
}
sort(lower.begin(), lower.end(), [&](int a, int b) {
return is_clockwise(2, a, b);
});
lower.push_back(1);
vector<int> lower_hull = {2};
for (auto &i : lower) {
while ((int) lower_hull.size() >= 2 && is_clockwise(i, lower_hull.back(), lower_hull[(int) lower_hull.size() - 2])) lower_hull.pop_back();
lower_hull.push_back(i);
}
reverse(lower_hull.begin(), lower_hull.end());
upper_hull.pop_back();
while (1) {
if ((int) lower_hull.size() >= 2 && (int) upper_hull.size() >= 1 && is_clockwise(lower_hull[(int) lower_hull.size() - 2], lower_hull.back(),
upper_hull.back())) {
lower_hull.pop_back();
continue;
}
if ((int) upper_hull.size() >= 2 && (int) lower_hull.size() >= 1 && is_clockwise(lower_hull.back(), upper_hull.back(),
upper_hull[(int) upper_hull.size() - 2])) {
upper_hull.pop_back();
continue;
}
break;
}
reverse(lower_hull.begin(), lower_hull.end());
reverse(upper_hull.begin(), upper_hull.end());
upper_hull.pop_back();
while (1) {
if ((int) lower_hull.size() >= 2 && (int) upper_hull.size() >= 1 && is_clockwise(lower_hull.back(), lower_hull[(int) lower_hull.size() - 2]
, upper_hull.back())) {
lower_hull.pop_back();
continue;
}
if ((int) upper_hull.size() >= 2 && (int) lower_hull.size() >= 1 && is_clockwise(lower_hull.back(), upper_hull[(int) upper_hull.size() - 2],
upper_hull.back())) {
upper_hull.pop_back();
continue;
}
break;
}
give_answer((int) lower_hull.size() + (int) upper_hull.size());
return 0;
}
# | 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... |