From 3205c134e83497ed153b983e6ed4bc7fce805af7 Mon Sep 17 00:00:00 2001 From: jung0115 Date: Sat, 28 Sep 2024 03:08:16 +0900 Subject: [PATCH] 2024-09-28 --- jung0115/README.md | 3 +- .../Baekjoon_12015.java" | 55 +++++++++++++++++++ .../Baekjoon_1477.kt" | 0 .../Programmers_43238.kt" | 0 4 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 "jung0115/\354\235\264\353\266\204\355\203\220\354\203\211/Baekjoon_12015.java" rename "jung0115/\354\235\264\353\266\204 \355\203\220\354\203\211/Baekjoon_1477.kt" => "jung0115/\354\235\264\353\266\204\355\203\220\354\203\211/Baekjoon_1477.kt" (100%) rename "jung0115/\354\235\264\353\266\204 \355\203\220\354\203\211/Programmers_43238.kt" => "jung0115/\354\235\264\353\266\204\355\203\220\354\203\211/Programmers_43238.kt" (100%) diff --git a/jung0115/README.md b/jung0115/README.md index d434c325..91937fe3 100644 --- a/jung0115/README.md +++ b/jung0115/README.md @@ -15,4 +15,5 @@ | 11차시 | 2024.09.04.수 | 수학 | [축구(1344)](https://www.acmicpc.net/problem/1344) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/153 | | 12차시 | 2024.09.07.토 | 다이나믹 프로그래밍 | [개근상(1563)](https://www.acmicpc.net/problem/1563) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/157 | | 13차시 | 2024.09.23.월 | 다이나믹 프로그래밍 | [사전(1256)](https://www.acmicpc.net/problem/1256) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/162 | -| 14차시 | 2024.09.25.수 | 그리디 알고리즘 | [컵라면(1781)](https://www.acmicpc.net/problem/1781) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/165 | \ No newline at end of file +| 14차시 | 2024.09.25.수 | 그리디 알고리즘 | [컵라면(1781)](https://www.acmicpc.net/problem/1781) | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/165 | +| 15차시 | 2024.09.28.토 | 이분 탐색 | [가장 긴 증가하는 부분 수열 2(12015)](https://www.acmicpc.net/problem/12015) | | \ No newline at end of file diff --git "a/jung0115/\354\235\264\353\266\204\355\203\220\354\203\211/Baekjoon_12015.java" "b/jung0115/\354\235\264\353\266\204\355\203\220\354\203\211/Baekjoon_12015.java" new file mode 100644 index 00000000..afef76f8 --- /dev/null +++ "b/jung0115/\354\235\264\353\266\204\355\203\220\354\203\211/Baekjoon_12015.java" @@ -0,0 +1,55 @@ +package jung0115.이분탐색; +// 15차시 2024.09.28.토 : 백준 - 가장 긴 증가하는 부분 수열 2(12015) + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class Baekjoon_12015 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + int N = Integer.parseInt(br.readLine()); + StringTokenizer st = new StringTokenizer(br.readLine()); + + int[] A = new int[N]; + for(int i = 0; i < N; i++) { + A[i] = Integer.parseInt(st.nextToken()); + } + + int[] longIncrease = new int[N]; + int lastIndex = 0; + longIncrease[lastIndex] = A[0]; + + for(int i = 1; i < N; i++) { + int num = A[i]; + + // 이전값보다 큼 -> 증가 + if(longIncrease[lastIndex] < num) { + longIncrease[++lastIndex] = num; + } + // 이전값보다 작음 + else { + int left = 0; + int right = lastIndex + 1; + + while (left < right) { + int mid = (left + right) / 2; + + if(longIncrease[mid] < num) { + left = mid + 1; + } + else { + right = mid; + } + } + + // num보다 작은 값 중 제일 뒤에 있는 숫자의 뒤 + longIncrease[left] = num; + } + } + + System.out.print(lastIndex + 1); + } +} diff --git "a/jung0115/\354\235\264\353\266\204 \355\203\220\354\203\211/Baekjoon_1477.kt" "b/jung0115/\354\235\264\353\266\204\355\203\220\354\203\211/Baekjoon_1477.kt" similarity index 100% rename from "jung0115/\354\235\264\353\266\204 \355\203\220\354\203\211/Baekjoon_1477.kt" rename to "jung0115/\354\235\264\353\266\204\355\203\220\354\203\211/Baekjoon_1477.kt" diff --git "a/jung0115/\354\235\264\353\266\204 \355\203\220\354\203\211/Programmers_43238.kt" "b/jung0115/\354\235\264\353\266\204\355\203\220\354\203\211/Programmers_43238.kt" similarity index 100% rename from "jung0115/\354\235\264\353\266\204 \355\203\220\354\203\211/Programmers_43238.kt" rename to "jung0115/\354\235\264\353\266\204\355\203\220\354\203\211/Programmers_43238.kt"