제출 #945340

#제출 시각아이디문제언어결과실행 시간메모리
945340AiperiiiTriangles (CEOI18_tri)C++14
20 / 100
1 ms600 KiB
#include <bits/stdc++.h> //#include "trilib.h" #define ff first #define ss second #define pb push_back #define all(x) x.begin(),x.end() using namespace std; static int n; static long long *x, *y; static int queries=0; static void init() { static int is_inited=0; if (is_inited) return; is_inited=1; assert(scanf("%d", &n)==1); x=(long long*)malloc((n+1)*sizeof(long long)); y=(long long*)malloc((n+1)*sizeof(long long)); for (int i=1; i<=n; i++) assert(scanf("%lld%lld", &x[i], &y[i])==2); } int get_n() { init(); return n; } int is_clockwise(int a, int b, int c) { init(); assert(a>=1 && a<=n); assert(b>=1 && b<=n); assert(c>=1 && c<=n); assert(a!=b && a!=c && b!=c); queries++; if(queries == 1000 * 1000 + 1) printf("Too many queries!"); return (x[b]-x[a])*(y[c]-y[a])-(x[c]-x[a])*(y[b]-y[a])<0; } void give_answer(int s) { init(); printf("%d\n", s); } bool sorting(int x,int y) { return is_clockwise(x,1,y); } signed main(){ int n=get_n(); vector <int> v1,v2; for(int i=3;i<=n;i++){ if(is_clockwise(1,2,i))v1.pb(i); else v2.pb(i); } sort(all(v1),sorting); sort(all(v2),sorting); reverse(all(v1)); vector <int> hull2={1,2},hull1={1,2}; for(auto x : v2){ while(hull2.size()>1 && is_clockwise(hull2[hull2.size()-2],hull2[hull2.size()-1],x)){ hull2.pop_back(); } hull2.pb(x); } for(auto x : v1){ while(hull1.size()>1 && !is_clockwise(hull1[hull1.size()-2],hull1[hull1.size()-1],x)){ hull1.pop_back(); } hull1.pb(x); } hull2.pb(hull2.front()); hull2.erase(hull2.begin()); for(int i=hull1.size()-1;i>=2;i--){ int x=hull1[i]; while(hull2.size()>1 && is_clockwise(hull2[hull2.size()-2],hull2[hull2.size()-1],x)){ hull2.pop_back(); } hull2.pb(x); } while(hull2.size()>1 && is_clockwise(hull2[hull2.size()-2],hull2[hull2.size()-1],hull2[0])){ hull2.pop_back(); } reverse(all(hull2)); while(hull2.size()>1 && !is_clockwise(hull2[hull2.size()-2],hull2[hull2.size()-1],hull2[0])){ hull2.pop_back(); } give_answer(hull2.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...