From 51c247000c03d88b47a0aaefeb14a843e02c1b42 Mon Sep 17 00:00:00 2001 From: oncsr Date: Fri, 14 Feb 2025 22:33:50 +0900 Subject: [PATCH] =?UTF-8?q?[20250214]=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=EA=B6=8C=ED=98=81?= =?UTF-8?q?=EC=A4=80?= 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" | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 "khj20006/202502/14 BOJ G2 \343\205\213\343\205\213\353\243\250\343\205\213\343\205\213.md" diff --git "a/khj20006/202502/14 BOJ G2 \343\205\213\343\205\213\353\243\250\343\205\213\343\205\213.md" "b/khj20006/202502/14 BOJ G2 \343\205\213\343\205\213\353\243\250\343\205\213\343\205\213.md" new file mode 100644 index 00000000..723a488e --- /dev/null +++ "b/khj20006/202502/14 BOJ G2 \343\205\213\343\205\213\353\243\250\343\205\213\343\205\213.md" @@ -0,0 +1,66 @@ +```java + +import java.util.*; +import java.io.*; + +class Main { + + // IO field + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st; + + static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());} + static int nextInt() {return Integer.parseInt(st.nextToken());} + static long nextLong() {return Long.parseLong(st.nextToken());} + static void bwEnd() throws Exception {bw.flush();bw.close();} + + // Additional field + static String str; + static int[] left, right, R_cnt; + static int N; + + public static void main(String[] args) throws Exception { + + ready(); + solve(); + + bwEnd(); + + } + + static void ready() throws Exception{ + + str = new String("0"); // padding for prefix sum + str += br.readLine(); + str += "0"; + N = str.length()-2; + + left = new int[N+2]; + right = new int[N+2]; + R_cnt = new int[N+2]; + + } + + static void solve() throws Exception{ + + for(int i=1;i<=N;i++) left[i] += left[i-1] + (str.charAt(i) == 'K' ? 1 : 0); + for(int i=N;i>=1;i--) right[i] += right[i+1] + (str.charAt(i) == 'K' ? 1 : 0); + for(int i=1;i<=N;i++) R_cnt[i] += R_cnt[i-1] + (str.charAt(i) == 'R' ? 1 : 0); + + int ans = 0; + int s = 0, e = N+1, K_cnt = 0; + while(s=1 && right[e] < K_cnt) e--; + } + bw.write(ans+"\n"); + + } + +} + +```