From d417fc9fd64bf41d891c7add9ed19190c112ca64 Mon Sep 17 00:00:00 2001 From: Lee-JH <98592001+Lee-JoungHyun@users.noreply.github.com> Date: Fri, 6 Sep 2024 01:19:23 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=EC=A0=8A=EC=9D=80=20=EB=82=A0=EC=9D=98=20?= =?UTF-8?q?=EC=83=9D=EC=9D=B4=EC=97=AC=20/=2050=EB=B6=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Lee-JoungHyun/BOJ_18866.java | 61 ++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 Lee-JoungHyun/BOJ_18866.java diff --git a/Lee-JoungHyun/BOJ_18866.java b/Lee-JoungHyun/BOJ_18866.java new file mode 100644 index 0000000..6859ab5 --- /dev/null +++ b/Lee-JoungHyun/BOJ_18866.java @@ -0,0 +1,61 @@ +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.*; + +public class BOJ_18866. { + + public static void main(String[] args) throws Exception{ + + final int MAX = 1_000_000_001; + final int MIN = -1; + + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + int N = Integer.parseInt(br.readLine()); + + int[][] arr = new int[N + 1][2]; + + int[] minHappyLeft = new int[N + 2]; // 구간 1 ~ index의 최소 행복도 + int[] maxHappyRight = new int[N + 2]; // 구간 index ~ N의 최대 행복도 + + int[] maxFatigueLeft = new int[N + 2]; // 구간 1 ~ index의 최대 피로도 + int[] minFatigueRight = new int[N + 2]; // 구간 index ~ N의 최소 피로도 + + + minHappyLeft[0] = MAX; + maxHappyRight[N + 1] = MIN; + maxFatigueLeft[0] = MIN; + minFatigueRight[N + 1] = MAX; + + for (int i = 1; i <= N; i++) { + st = new StringTokenizer(br.readLine()); + arr[i][0] = Integer.parseInt(st.nextToken()); + arr[i][1] = Integer.parseInt(st.nextToken()); + + if(arr[i][0] != 0) minHappyLeft[i] = Math.min(minHappyLeft[i - 1], arr[i][0]); + else minHappyLeft[i] = minHappyLeft[i - 1]; + if(arr[i][1] != 0) maxFatigueLeft[i] = Math.max(maxFatigueLeft[i - 1], arr[i][1]); + else maxFatigueLeft[i] = maxFatigueLeft[i - 1]; + } + + for (int i = N; i >= 1; i--) { + if(arr[i][0] != 0) maxHappyRight[i] = Math.max(maxHappyRight[i + 1], arr[i][0]); + else maxHappyRight[i] = maxHappyRight[i + 1]; + if(arr[i][1] != 0) minFatigueRight[i] = Math.min(minFatigueRight[i + 1], arr[i][1]); + else minFatigueRight[i] = minFatigueRight[i + 1]; + } + + for (int i = N - 1; i >= 1; i--) { + // 1 ~ i년까지의 최소 행복도가 i+1 ~ N년의 최대 행복도보다 커야하며, + // 1 ~ i년까지의 최대 피로도가 i+1 ~ n년의 최소 피로도보다 작아야 한다. + if(minHappyLeft[i] >= maxHappyRight[i + 1] && maxFatigueLeft[i] <= minFatigueRight[i + 1]) { + System.out.println(i); + return; + } + } + + // 찾지 못한 경우 + System.out.println(-1); + } +} From 13862526cd58dd8a138b45822e53d3ca3d79b100 Mon Sep 17 00:00:00 2001 From: Lee-JH <98592001+Lee-JoungHyun@users.noreply.github.com> Date: Fri, 6 Sep 2024 01:20:07 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=ED=9A=8C=EC=A0=84=EC=B4=88=EB=B0=A5=20/=20?= =?UTF-8?q?50=EB=B6=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Lee-JoungHyun/BOJ_15961.java | 57 ++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 Lee-JoungHyun/BOJ_15961.java diff --git a/Lee-JoungHyun/BOJ_15961.java b/Lee-JoungHyun/BOJ_15961.java new file mode 100644 index 0000000..85bb9dc --- /dev/null +++ b/Lee-JoungHyun/BOJ_15961.java @@ -0,0 +1,57 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class BOJ_15961 { + static int N, c, k, d, arr[]; + static int[] visit = new int[3001]; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = null; + st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + d = Integer.parseInt(st.nextToken()); + k = Integer.parseInt(st.nextToken()); + c = Integer.parseInt(st.nextToken()); + arr = new int[N]; + for (int i = 0; i < N; i++) { + arr[i] = Integer.parseInt(br.readLine()); + } + + int cnt = 0; + int start = 0; + int end = k; + int answer = 1; + + for (int i = 0; i < end; i++) { + if (visit[arr[i]] == 0) { + cnt++; + } + visit[arr[i]]++; + } + visit[c] += 1; + // 전에 C가 있었음 = cnt에 반영이 되어있음 + answer = visit[c] > 1 ? cnt : ++cnt; + //System.out.println("0, 4 -> " + answer); + while (start <= N-1) { + + if (--visit[arr[start]] == 0) { + cnt--; + } + end++; + if (visit[arr[(end - 1) % N]] == 0) { + cnt++; + } + visit[arr[(end - 1) % N]]++; + start++; + + answer = Math.max(answer, cnt); + //System.out.println(start + ", " + end + " -> " + answer + "-" + cnt); + if (answer == k+1) + break; + } + System.out.println(answer); + } +}