Cowreography

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

요약
두 이진 문자열과 최대 교환 거리 K가 주어질 때, 첫 문자열을 마지막 문자열로 바꾸는 데 필요한 최소 교환 횟수를 구한다.
난이도

어려움10점 중 8점

유형
그리디, 투 포인터, 수학, 구현
정답자
아직 제출이 없습니다

문제

The cows have formed a dance team, and Farmer John is their choreographer! The team's latest and greatest dance involves NN cows (2≤N≤1062 \le N \le 10^6) standing in a line. Each move in the dance involves two cows, up to KK positions apart (1≤K<N1 \le K < N), gracefully jumping and landing in each other's position.

There are two types of cows in the line – Guernseys and Holsteins. As such, Farmer John has documented the dance as a sequence of length-NN binary strings, where a 00 represents a Guernsey, a 11 represents a Holstein, and the overall string represents how the cows are arranged in the line.

Unfortunately, Farmer Nhoj (who choreographs for a rival team) has sabotaged the dance and erased all but the first and last binary strings! With a big competition quickly approaching, Farmer John must waste no time in reconstructing the dance.

Given these two binary strings, help Farmer John find the minimum number of moves in the dance!

입력

The first line contains NN and KK.

The second line contains the first binary string.

The third line contains the last binary string.

It is guaranteed that both binary strings contain the same number of ones.

출력

The minimum number of moves in the dance.

예제3

  1. 예제 1

    입력
    4 1
    0111
    1110
    
    예상 출력
    3
    
  2. 예제 2

    입력
    5 2
    11000
    00011
    
    예상 출력
    3
    
  3. 예제 3

    입력
    5 4
    11000
    00011
    
    예상 출력
    2