From 90adac3efadae950d1959062225613b43c5e95f8 Mon Sep 17 00:00:00 2001 From: Ukj0ng <90972240+Ukj0ng@users.noreply.github.com> Date: Tue, 14 Oct 2025 07:55:14 +0900 Subject: [PATCH] =?UTF-8?q?[20251014]=20BOJ=20/=20G4=20/=20=EA=B3=A0?= =?UTF-8?q?=EB=83=A5=EC=9D=B4=20/=20=ED=95=9C=EC=A2=85=EC=9A=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4 \352\263\240\353\203\245\354\235\264.md" | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 "Ukj0ng/202510/14 BOJ G4 \352\263\240\353\203\245\354\235\264.md" diff --git "a/Ukj0ng/202510/14 BOJ G4 \352\263\240\353\203\245\354\235\264.md" "b/Ukj0ng/202510/14 BOJ G4 \352\263\240\353\203\245\354\235\264.md" new file mode 100644 index 00000000..99a95fb4 --- /dev/null +++ "b/Ukj0ng/202510/14 BOJ G4 \352\263\240\353\203\245\354\235\264.md" @@ -0,0 +1,58 @@ +``` +import java.io.*; +import java.util.*; + +public class Main { + private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + private static Map map; + private static char[] input; + private static int N; + public static void main(String[] args) throws IOException { + init(); + + int answer = twoPointer(); + + bw.write(answer + "\n"); + bw.flush(); + bw.close(); + br.close(); + } + + private static void init() throws IOException { + N = Integer.parseInt(br.readLine()); + map = new HashMap<>(); + input = br.readLine().toCharArray(); + } + + private static int twoPointer() { + int left = 0; + int right = 0; + int max = 0; + int count = 0; + + while (left < input.length) { + if (right < input.length && valid(input[right])) { + map.put(input[right], map.getOrDefault(input[right], 0)+1); + count++; + max = Math.max(max, count); + right++; + } else { + map.put(input[left], map.get(input[left])-1); + if (map.get(input[left]) == 0) { + map.remove(input[left]); + } + left++; + count--; + } + } + + return max; + } + + private static boolean valid(char c) { + return (map.containsKey(c) && map.size() <= N) || (!map.containsKey(c) && map.size() < N); + } + +} +```