From 78911c64d03688e6faffb3199f700367d2a0d2dc Mon Sep 17 00:00:00 2001 From: Ukj0ng <90972240+Ukj0ng@users.noreply.github.com> Date: Fri, 17 Oct 2025 22:38:20 +0900 Subject: [PATCH] =?UTF-8?q?[20251017]=20BOJ=20/=20G2=20/=20=E3=85=8B?= =?UTF-8?q?=E3=85=8B=EB=A3=A8=E3=85=8B=E3=85=8B=20/=20=ED=95=9C=EC=A2=85?= =?UTF-8?q?=EC=9A=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...13\353\243\250\343\205\213\343\205\213.md" | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 "Ukj0ng/202510/17 BOJ G2 \343\205\213\343\205\213\353\243\250\343\205\213\343\205\213.md" diff --git "a/Ukj0ng/202510/17 BOJ G2 \343\205\213\343\205\213\353\243\250\343\205\213\343\205\213.md" "b/Ukj0ng/202510/17 BOJ G2 \343\205\213\343\205\213\353\243\250\343\205\213\343\205\213.md" new file mode 100644 index 00000000..ad7c8d7f --- /dev/null +++ "b/Ukj0ng/202510/17 BOJ G2 \343\205\213\343\205\213\353\243\250\343\205\213\343\205\213.md" @@ -0,0 +1,70 @@ +``` +import java.io.*; + +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 char[] input; + private static int[] a; + private static int total, answer, rCount; + + public static void main(String[] args) throws IOException { + init(); + answer = twoPointer(); + + bw.write(answer + "\n"); + bw.flush(); + bw.close(); + br.close(); + } + + private static void init() throws IOException { + input = br.readLine().toCharArray(); + + rCount = 0; + for (char c : input) { + if (c == 'R') rCount++; + } + + a = new int[rCount]; + + int idx = 0; + int kCount = 0; + + for (int i = 0; i < input.length; i++) { + if (input[i] == 'K') { + total++; + kCount++; + } else { + a[idx++] = kCount; + } + } + } + + private static int twoPointer() { + if (rCount == 0) return 0; + + int left = 0; + int right = rCount - 1; + int max = 0; + + while (left <= right) { + int leftK = a[left]; + int rightK = total - a[right]; + + int k = Math.min(leftK, rightK); + int r = right - left + 1; + + max = Math.max(max, k * 2 + r); + + if (leftK < rightK) { + left++; + } else { + right--; + } + } + + return max; + } +} +```