From 064b778a50c455b1b76a9a8a1a16e349740b8fb8 Mon Sep 17 00:00:00 2001 From: Ukj0ng <90972240+Ukj0ng@users.noreply.github.com> Date: Sat, 13 Dec 2025 19:00:24 +0900 Subject: [PATCH] =?UTF-8?q?[20251213]=20BOJ=20/=20G2=20/=20=EB=B0=98?= =?UTF-8?q?=EB=8F=84=EC=B2=B4=20=EC=84=A4=EA=B3=84=20/=20=ED=95=9C?= =?UTF-8?q?=EC=A2=85=EC=9A=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\354\262\264 \354\204\244\352\263\204.md" | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 "Ukj0ng/202512/13 BOJ G2 \353\260\230\353\217\204\354\262\264 \354\204\244\352\263\204.md" diff --git "a/Ukj0ng/202512/13 BOJ G2 \353\260\230\353\217\204\354\262\264 \354\204\244\352\263\204.md" "b/Ukj0ng/202512/13 BOJ G2 \353\260\230\353\217\204\354\262\264 \354\204\244\352\263\204.md" new file mode 100644 index 00000000..f68e5f61 --- /dev/null +++ "b/Ukj0ng/202512/13 BOJ G2 \353\260\230\353\217\204\354\262\264 \354\204\244\352\263\204.md" @@ -0,0 +1,67 @@ +``` +import java.io.*; +import java.util.StringTokenizer; + +public class Main { + private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + private static int[] arr, lis; + private static int N; + + public static void main(String[] args) throws IOException { + init(); + int answer = DP(); + + bw.write(answer + "\n"); + bw.flush(); + bw.close(); + br.close(); + } + + private static void init() throws IOException { + N = Integer.parseInt(br.readLine()); + + StringTokenizer st = new StringTokenizer(br.readLine()); + arr = new int[N]; + lis = new int[N]; + + for (int i = 0; i < N; i++) { + arr[i] = Integer.parseInt(st.nextToken()); + } + } + + private static int DP() { + int len = 0; + + for (int i = 0; i < N; i++) { + int key = arr[i]; + + if (len == 0 || lis[len-1] < key) { + lis[len] = key; + len++; + } else { + int index = binarySearch(len-1, key); + lis[index] = key; + } + } + + return len; + } + + private static int binarySearch(int right, int key) { + int left = 0; + + while (left < right) { + int mid = left + (right-left)/2; + + if (lis[mid] >= key) { + right = mid; + } else { + left = mid+1; + } + } + + return right; + } +} +```