From 924c6bcb3e34504d0b6da665a552dcc15bc2a42a Mon Sep 17 00:00:00 2001 From: oncsr Date: Wed, 16 Apr 2025 13:45:40 +0900 Subject: [PATCH] =?UTF-8?q?[20250416]=20BOJ=20/=20G1=20/=20=EC=A2=8B?= =?UTF-8?q?=EC=9D=80=20=EC=88=98=20/=20=EA=B6=8C=ED=98=81=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ... \354\242\213\354\235\200 \354\210\230.md" | 120 ++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 "khj20006/202504/16 BOJ G1 \354\242\213\354\235\200 \354\210\230.md" diff --git "a/khj20006/202504/16 BOJ G1 \354\242\213\354\235\200 \354\210\230.md" "b/khj20006/202504/16 BOJ G1 \354\242\213\354\235\200 \354\210\230.md" new file mode 100644 index 00000000..80c53472 --- /dev/null +++ "b/khj20006/202504/16 BOJ G1 \354\242\213\354\235\200 \354\210\230.md" @@ -0,0 +1,120 @@ +```java + +import java.util.*; +import java.io.*; + +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 = new StringTokenizer(""); + + static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());} + static String nextToken() throws Exception { + while(!st.hasMoreTokens()) nextLine(); + return st.nextToken(); + } + static int nextInt() throws Exception { return Integer.parseInt(nextToken()); } + static long nextLong() throws Exception { return Long.parseLong(nextToken()); } + static double nextDouble() throws Exception { return Double.parseDouble(nextToken()); } + static void bwEnd() throws Exception {bw.flush();bw.close();} + + // Additional field + + static class Node{ + long cnt, left, right, diff; + int val; + Node(long cnt, int val, long left, long right, long diff){ + this.cnt = cnt; + this.val = val; + this.left = left; + this.right = right; + this.diff = diff; + } + } + + static int L, N; + static int[] A; + static int INF = 1010101010; + static TreeSet V; + + public static void main(String[] args) throws Exception { + + ready(); + solve(); + + bwEnd(); + + } + + static void ready() throws Exception{ + + L = nextInt(); + A = new int[L]; + for(int i=0;i(); + + } + + static void solve() throws Exception{ + + PriorityQueue PQ = new PriorityQueue<>((a,b) -> { + if(a.right == INF) { + if(b.right == INF) return a.val-b.val; + return 1; + } + if(b.right == INF) return -1; + if(a.cnt == b.cnt) return a.val-b.val; + if(a.cnt < b.cnt) return -1; + return 1; + }); + + Arrays.sort(A); + List zeros = new ArrayList<>(); + if(A[0] > 2) { + PQ.add(new Node(cal(1,A[0]-1,1), 1, 1, A[0]-1, 1)); + PQ.add(new Node(cal(1,A[0]-1,A[0]-1), A[0]-1, 1, A[0]-1, -1)); + } + else if(A[0] == 2) zeros.add(1); + for(int i=0;i0) { + Node now = PQ.poll(); + if(V.contains(now.val)) continue; + V.add(now.val); + bw.write(now.val + " "); + N--; + Node copy = new Node(now.cnt, now.val, now.left, now.right, now.diff); + copy.val += copy.diff; + if(copy.left > copy.val || copy.right < copy.val) continue; + copy.cnt = cal(copy.left, copy.right, copy.val); + PQ.add(copy); + } + + } + + static long cal(long l, long r, long x) { + return (x-l+1)*(r-x+1); + } + +} + +```