-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ19941.java
More file actions
36 lines (33 loc) · 1.16 KB
/
BOJ19941.java
File metadata and controls
36 lines (33 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class BOJ19941 {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int cnt = 0;
int N = Integer.parseInt(st.nextToken());
int K = Integer.parseInt(st.nextToken());
char[] arr = new char[N];
boolean[] ate = new boolean[N];
String str = br.readLine();
for(int i = 0; i < N; i++){
arr[i] = str.charAt(i);
}
for(int i = 0; i < str.length(); i++){
if(arr[i] == 'P'){
int start = Math.max(i-K, 0);
int end = Math.min(i+K, N-1);
for(int j = start; j <= end; j++){
if(arr[j] == 'H' && !ate[j]){
ate[j] = true;
cnt++;
break;
}
}
}
}
System.out.print(cnt);
}
}