From 1f08ed81c2e8ff865ae976f36d9f9f1cff4547c3 Mon Sep 17 00:00:00 2001 From: oncsr Date: Wed, 5 Feb 2025 21:52:07 +0900 Subject: [PATCH] =?UTF-8?q?[20250205]=20BOJ=20/=20=ED=94=8C=EB=9E=983=20/?= =?UTF-8?q?=20=EB=8B=AC=EB=A6=AC=EA=B8=B0=20=EC=BD=94=EC=8A=A4=20/=20?= =?UTF-8?q?=EA=B6=8C=ED=98=81=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\352\270\260 \354\275\224\354\212\244.md" | 120 ++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 "khj20006/202502/05 BOJ P3 \353\213\254\353\246\254\352\270\260 \354\275\224\354\212\244.md" diff --git "a/khj20006/202502/05 BOJ P3 \353\213\254\353\246\254\352\270\260 \354\275\224\354\212\244.md" "b/khj20006/202502/05 BOJ P3 \353\213\254\353\246\254\352\270\260 \354\275\224\354\212\244.md" new file mode 100644 index 00000000..0e8d8844 --- /dev/null +++ "b/khj20006/202502/05 BOJ P3 \353\213\254\353\246\254\352\270\260 \354\275\224\354\212\244.md" @@ -0,0 +1,120 @@ +```java + +import java.util.*; +import java.io.*; + +class Point{ + long x,y; + Point(long x, long y){ + this.x = x; + this.y = y; + } +} + +class Main { + + // IO field + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st; + + static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());} + static int nextInt() {return Integer.parseInt(st.nextToken());} + static long nextLong() {return Long.parseLong(st.nextToken());} + static void bwEnd() throws Exception {bw.flush();bw.close();} + + // Additional field + static Point[] arr; + static Point[] convexHull; + + + static int N; + static long ans = 0; + + // positive : ccw + static int ccw(Point a, Point b, Point c) { + long res = (a.x*b.y + b.x*c.y + c.x*a.y) - (b.x*a.y + c.x*b.y + a.x*c.y); + if(res > 0) return 1; + if(res < 0) return -1; + return 0; + } + + public static void main(String[] args) throws Exception { + + input(); + + if(N <= 2) { + if(N == 1) bw.write("0"); + else { + long dx = arr[0].x - arr[1].x; + long dy = arr[0].y - arr[1].y; + bw.write((dx*dx+dy*dy) + "\n"); + } + bwEnd(); + return; + } + + constructConvexHull(); + + rotate(); + + bw.write(ans+"\n"); + + bwEnd(); + } + + static void input() throws Exception { + nextLine(); + N = nextInt(); + arr = new Point[N]; + for(int i=0;i { + if(a.x==b.x) return (int)(a.y-b.y); + return (int)(a.x-b.x); + }); + List lowerHull = new ArrayList<>(); + List upperHull = new ArrayList<>(); + for(Point p : arr) { + while(lowerHull.size()>1 && ccw(lowerHull.get(lowerHull.size()-2), lowerHull.get(lowerHull.size()-1), p) <= 0) lowerHull.remove(lowerHull.size()-1); + lowerHull.add(p); + while(upperHull.size()>1 && ccw(upperHull.get(upperHull.size()-2), upperHull.get(upperHull.size()-1), p) >= 0) upperHull.remove(upperHull.size()-1); + upperHull.add(p); + } + + convexHull = new Point[lowerHull.size() + upperHull.size() - 2]; + int idx = 0; + for(Point p : upperHull) convexHull[idx++] = p; + idx--; + for(int i=lowerHull.size()-1;i>0;i--) convexHull[idx++] = lowerHull.get(i); + + } + + static void rotate() { + int p = 1, sz = convexHull.length; + for(int i=0;i