-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB5525.java
More file actions
52 lines (42 loc) · 1 KB
/
B5525.java
File metadata and controls
52 lines (42 loc) · 1 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package Practice;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class B5525 { //IOIOI
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
int M = Integer.parseInt(br.readLine());
String s = br.readLine();
boolean isIOI = false;
int ans = 0, countI = 0, countO = 0;
for(int i = 0; i < M; i++) {
if(s.charAt(i) == 'O' && countI == countO + 1) {
countO++;
continue;
}
if(s.charAt(i) == 'O') {
countI = 0;
countO = 0;
isIOI = false;
continue;
}
if(s.charAt(i) == 'I' && countI == countO) {
countI++;
if(!isIOI && countI == N + 1) {
isIOI = true;
ans++;
}
else if(isIOI) ans++;
continue;
}
if(s.charAt(i) == 'I') {
countI = 1;
countO = 0;
isIOI = false;
continue;
}
}
System.out.println(ans);
}
}