Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 828dfb3

Browse files
committed
고다혜: [BOJ] 15831 준표의 조약돌_241122
1 parent 78db452 commit 828dfb3

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

‎BOJ/15001-20000번/DH_15831.java‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
/*
5+
* 준표의 조약돌
6+
*/
7+
8+
public class DH_15831 {
9+
public static void main(String[] args) throws Exception {
10+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
11+
StringTokenizer st = new StringTokenizer(br.readLine());
12+
13+
int N = Integer.parseInt(st.nextToken()); // 조약돌의 총 개수
14+
int B = Integer.parseInt(st.nextToken()); // 검은 조약돌의 최대 개수
15+
int W = Integer.parseInt(st.nextToken()); // 하얀 조약돌의 최소 개수
16+
17+
String str = br.readLine();
18+
19+
int s = 0, e = 0, bCnt = 0, wCnt = 0, answer = 0;
20+
21+
while(e < N) {
22+
if(B < bCnt) { // 검정 조약돌의 개수가 크다면 start 지점 오른쪽으로
23+
if(str.charAt(s) == 'B') bCnt -= 1;
24+
else wCnt -= 1;
25+
s += 1;
26+
} else { // 하얀 조약돌의 개수가 작다면 end 지점 오른쪽으로
27+
if(str.charAt(e) == 'B') bCnt += 1;
28+
else wCnt += 1;
29+
30+
e += 1;
31+
}
32+
33+
if(bCnt <= B && wCnt >= W) answer = Math.max(answer, e - s);
34+
}
35+
36+
System.out.println(answer);
37+
}
38+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /