Streaming Services

면접 대비

시간 제한2초메모리 제한512 MB

요약
각 날짜에 어느 스트리밍 서비스가 에피소드를 공개하는지 나타내는 문자열이 주어질 때, 길이 K인 구독을 사서 매일 공개를 시청할 수 있도록 하면서 구독 구매 횟수를 최소화한다.
난이도

보통10점 중 6점

유형
그리디, 구현, 배열, 동적 계획법
정답자
아직 제출이 없습니다

문제

Last year, you finally went ahead and became a cord-cutter, cancelling your TV subscription to avoid all the annoying ads. This was a relief. Suddenly, you could watch TV whenever you wanted, rather than when the TV channels dictated it. Of course, this new-found happiness was short-lived. The streaming services quickly started adapting the old "one episode a week" paradigm that the old TV channels were based on, and suddenly the conversations during lunch at work started revolving around the episodes released on the previous day on the streaming services.

A streaming service works like this. At some specific days, a service will release exactly one new episode of a TV show. Every day, you need to watch an episode that was released during this day, so you can join in on the lunch conversations the day after.

Since your favourite streaming service may sometimes not release an episode, you plan to use two streaming services instead. At any given day, you can buy a subscription of a service that you do not currently subscribe to. A subscription runs for KK days, and during each of these days, you can watch episodes on the streaming service you just bought a subscription for. Even if you have an active subscription for a service, you may purchase a subscription for the other service.

Given the dates when each service releases a new episode for the following NN days, determine the total number of subscription periods you need to buy to each day have an active subscription for a service that releases a new episode.

입력

The first line contains NN, the number of days you have the release schedule for, and KK, the number of days each subscription runs for (1≤K≤N1 \le K \le N). The next line contains a string of NN characters, consisting only of characters 1, 2 or B.

The ii'th character describes whether a new episode is released on the first service (1), second service (2), or both services (B) on day ii.

출력

Output a single integer; the number of times you need to purchase a streaming service subscription to watch a newly released episode each day.

제한

  • N≤400,000N \le 400\\,000

예제2

  1. 예제 1

    입력
    3 2
    121
    
    예상 출력
    3
    
  2. 예제 2

    입력
    8 3
    1B21B212
    
    예상 출력
    5