ps | |
---|---|
링크 | acmicpc.net/… |
출처 | BOJ |
문제 번호 | 5525 |
문제명 | IOIOI |
레벨 | 실버 2 |
분류 |
애드혹 |
시간복잡도 | O(n) |
인풋사이즈 | n<=1,000,000 |
사용한 언어 | Python |
제출기록 | 31156KB / 184ms |
최고기록 | 140ms |
해결날짜 | 2021/08/09 |
"""Solution code for "BOJ 5525. IOIOI".
- Problem link: https://www.acmicpc.net/problem/5525
- Solution link: http://www.teferi.net/ps/problems/boj/5525
Tags: [RegEx]
"""
import re
def main():
N = int(input())
M = int(input()) # pylint: disable=unused-variable
S = input()
matches = re.finditer('I(OI)+', S)
answer = sum(max(0, (m.end() - m.start()) // 2 - N + 1) for m in matches)
print(answer)
if __name__ == '__main__':
main()
"""Solution code for "BOJ 5525. IOIOI".
- Problem link: https://www.acmicpc.net/problem/5525
- Solution link: http://www.teferi.net/ps/problems/boj/5525
"""
def main():
N = int(input())
M = int(input()) # pylint: disable=unused-variable
S = input()
answer = 0
cur_pattern_len = 0
prev = 'O'
for cur in S:
if cur == prev:
cur_pattern_len = 0
elif cur == 'O':
cur_pattern_len += 1
elif cur_pattern_len >= N:
answer += 1
prev = cur
print(answer)
if __name__ == '__main__':
main()