Logo
(追記) (追記ここまで)

31766번 - Cowreography 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB148443932.773%

문제

The cows have formed a dance team, and Farmer John is their choreographer! The team's latest and greatest dance involves $N$ cows (2ドル \le N \le 10^6$) standing in a line. Each move in the dance involves two cows, up to $K$ positions apart (1ドル \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-$N$ binary strings, where a 0ドル$ represents a Guernsey, a 1ドル$ 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 $N$ and $K$.

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.

제한

예제 입력 1

4 1
0111
1110

예제 출력 1

3

One possible dance:

0111 -> 1011 -> 1101 -> 1110

예제 입력 2

5 2
11000
00011

예제 출력 2

3

One possible dance:

11000 -> 01100 -> 00110 -> 00011

예제 입력 3

5 4
11000
00011

예제 출력 3

2

One possible dance:

11000 -> 10010 -> 00011

힌트

출처

Olympiad > USA Computing Olympiad > 2023-2024 Season > USACO 2024 US Open Contest > Gold 1번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /