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 781b714

Browse files
committed
배수빈: [BOJ] 15831 준표의 조약돌_2411122
1 parent deea593 commit 781b714

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import java.io.BufferedReader;
2+
import java.io.IOException;
3+
import java.io.InputStreamReader;
4+
import java.util.StringTokenizer;
5+
6+
public class SB_15831 {
7+
static int N, B, W;
8+
static int[] walks;
9+
static int[] pebb = new int[2]; // 0:흰돌, 1:검정
10+
static int mx = 0;
11+
public static void main(String[] args) throws IOException {
12+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
13+
StringTokenizer st = new StringTokenizer(br.readLine());
14+
15+
N = Integer.parseInt(st.nextToken());
16+
B = Integer.parseInt(st.nextToken()); // 검정 최대 개수
17+
W = Integer.parseInt(st.nextToken()); // 흰색 최소 개수
18+
19+
walks = new int[N];
20+
String line = br.readLine();
21+
for (int i = 0; i < N; i++) {
22+
char c = line.charAt(i);
23+
walks[i] = (c == 'W') ? 0 : 1;
24+
}
25+
26+
int left = 0;
27+
int right = 0;
28+
while (right < N) {
29+
pebb[walks[right]]++; // 오른쪽에 해당하는 색의 돌++
30+
31+
while (pebb[1]>B){ // 더이상 못갈경우 조건만족할때까지 left빼기
32+
pebb[walks[left]]--;
33+
left++;
34+
}
35+
36+
if (pebb[0] >= W){ // 흰돌 만족하면 거리 갱신
37+
mx = Math.max(mx, right - left + 1);
38+
}
39+
right++;
40+
}
41+
System.out.println(mx);
42+
}
43+
}

0 commit comments

Comments
(0)

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