제출 #95997

#제출 시각아이디문제언어결과실행 시간메모리
95997youngyojunTriangles (CEOI18_tri)C++11
100 / 100
29 ms2372 KiB
#include "trilib.h" #include <bits/stdc++.h> #define eb emplace_back #define sz(V) ((int)(V).size()) #define befv(V) ((V)[sz(V)-2]) #define allv(V) ((V).begin()),((V).end()) #define sorv(V) sort(allv(V)) #define univ(V) (V).erase(unique(allv(V)),(V).end()) using namespace std; int ccw(int a, int b, int c) { if(a == b || b == c || c == a) return 0; return is_clockwise(a, b, c) ? 1 : -1; } vector<int> LV, RV; int N; void f(vector<int> &V) { sort(V.begin()+1, V.end(), [&](int a, int b) { return 0 < ccw(V[0], a, b); }); vector<int> T; for(int v : V) { for(; 1 < sz(T) && ccw(befv(T), T.back(), v) <= 0; T.pop_back()); T.eb(v); } swap(V, T); } int main() { N = get_n(); LV.eb(1); RV.eb(2); for(int i = 3; i <= N; i++) (0 < ccw(1, 2, i) ? LV : RV).eb(i); f(LV); f(RV); int al = 0, ar = 0, bl = 0, br = 0, ln = sz(LV), rn = sz(RV); for(bool flag;;) { flag = false; for(; 0 < ccw(LV[al], RV[ar], LV[(al+1)%ln]); al=(al+1)%ln) flag = true; for(; 0 < ccw(LV[al], RV[ar], RV[(ar-1+rn)%rn]); ar=(ar-1+rn)%rn) flag = true; if(!flag) break; } for(bool flag;;) { flag = false; for(; ccw(LV[bl], RV[br], LV[(bl-1+ln)%ln]) < 0; bl=(bl-1+ln)%ln) flag = true; for(; ccw(LV[bl], RV[br], RV[(br+1)%rn]) < 0; br=(br+1)%rn) flag = true; if(!flag) break; } vector<int> Ans; for(int i = br;; i = (i+1)%rn) { Ans.eb(RV[i]); if(i == ar) break; } for(int i = al;; i = (i+1)%ln) { Ans.eb(LV[i]); if(i == bl) break; } sorv(Ans); univ(Ans); give_answer(sz(Ans)); return 0; }
#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...