This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "trilib.h"
#include <vector>
#include <algorithm>
using namespace std;
int ccw(int x, int y, int z) {
return is_clockwise(x + 1, y + 1, z + 1);
}
void _sort(vector<int> &v, int l, int r, bool counterclockwise) {
if (l >= r) return;
int m = (l + r) / 2;
_sort(v, l, m, counterclockwise);
_sort(v, m + 1, r, counterclockwise);
vector<int> u;
int x = l, y = m + 1;
while (x <= m && y <= r) {
if ((ccw(v[x], v[0], v[y]) > 0) ^ counterclockwise) u.push_back(v[x++]);
else u.push_back(v[y++]);
}
while (x <= m) u.push_back(v[x++]);
while (y <= r) u.push_back(v[y++]);
for (int i = 0; i < (int)u.size(); i++) v[l + i] = u[i];
}
int hull(vector<int> &v) {
vector<int> st;
st.push_back(0);
st.push_back(1);
for (int i = 2; i < (int)v.size(); i++) {
while ((int)st.size() > 1) {
int first = st.back(); st.pop_back();
int second = st.back();
if (ccw(v[second], v[first], v[i]) < 0) {
st.push_back(first);
break;
}
}
st.push_back(i);
}
int k = 0;
while (true) {
while (ccw(v[st.back()], v[st[k]], v[st[k + 1]]) > 0) k++;
if (ccw(v[st[(int)st.size() - 2]], v[st.back()], v[st[k]]) > 0) st.pop_back();
else break;
}
return (int)st.size() - k;
}
int main() {
int n = get_n();
vector<int> a, b;
a = { 0, 1 };
b = { 0, 1 };
for (int i = 2; i < n; i++) {
if (ccw(0, 1, i) > 0) a.push_back(i);
else b.push_back(i);
}
_sort(a, 1, (int)a.size() - 1, 1);
_sort(b, 1, (int)b.size() - 1, 0);
vector<int> z;
z.push_back(0);
reverse(a.begin(), a.end());
for (auto &i: a) if (i > 1) z.push_back(i);
z.push_back(1);
for (auto &i: b) if (i > 1) z.push_back(i);
give_answer(hull(z));
}
# | 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... |