From 99f48c6c95fea8516b97999665a23d86b5187387 Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Sat, 5 Jul 2025 23:35:31 +0900 Subject: [PATCH] =?UTF-8?q?[20250705]=20BOJ=20/=20G4=20/=20=EA=B3=A0?= =?UTF-8?q?=EB=83=A5=EC=9D=B4=20/=20=EA=B9=80=EC=88=98=EC=97=B0?= 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" | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 "suyeun84/202507/05 BOJ G4 \352\263\240\353\203\245\354\235\264.md" diff --git "a/suyeun84/202507/05 BOJ G4 \352\263\240\353\203\245\354\235\264.md" "b/suyeun84/202507/05 BOJ G4 \352\263\240\353\203\245\354\235\264.md" new file mode 100644 index 00000000..e0e58f22 --- /dev/null +++ "b/suyeun84/202507/05 BOJ G4 \352\263\240\353\203\245\354\235\264.md" @@ -0,0 +1,25 @@ +```java +import java.io.*; + +public class boj16472 { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + public static void main(String[] args) throws Exception { + int N = Integer.parseInt(br.readLine()); + String input = br.readLine(); + int[] alpha = new int[26]; + int cnt = 0, answer = 0, start = 0, end = -1; + + while (++end < input.length()) { + if (alpha[input.charAt(end) - 'a']++ == 0) cnt++; + + while (N < cnt) { + if (--alpha[input.charAt(start++) - 'a'] == 0) cnt--; + } + + answer = Math.max(answer, end - start + 1); + } + System.out.println(answer); + } +} +```