제출 #266576

#제출 시각아이디문제언어결과실행 시간메모리
266576islingrTriangles (CEOI18_tri)C++17
100 / 100
35 ms2680 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...