티스토리 뷰

PS/boj

boj)5525 - IOIOI

kingsubin 2020. 11. 17. 11:44
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
import java.io.*;
 
public class boj_5525 {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static int n, m, ans;
    static int[] dp;
    static String s;
 
    public static void main(String[] args) throws IOException {
        n = Integer.parseInt(br.readLine());
        m = Integer.parseInt(br.readLine());
        s = br.readLine();
 
        dp = new int[m];
        for (int i = 2; i < m; i++) {
            if (s.substring(i-2, i+1).equals("IOI")) {
                dp[i] = dp[i-2+ 1;
            }
 
            if (dp[i] >= n) {
                ans++;
            }
        }
 
        System.out.println(ans);
    }
}
cs

 

- DP / 문자열

- 어렵다.

 

- 조건이 100만이라 시간 제한 걸려서 안될거는 알았는데 어떻게 접근해야할지 모르겠었다.

- 다른 풀이 방법도 있던데 dp가 그나마 익숙해서 dp로 풀었다.

 

 

 

 


www.acmicpc.net/problem/5525

'PS > boj' 카테고리의 다른 글

boj)15652 - N과 M (4)  (0) 2020.11.17
boj)1654 - 랜선 자르기  (0) 2020.11.17
boj)15651 - N과 M (3)  (0) 2020.11.16
boj)15650 - N과 M (2)  (0) 2020.11.16
boj)15649 - N과 M (1)  (0) 2020.11.16