logo AlgoBeat OnlineJudge
登录 注册

#209971. [USACO24OPEN] Cowreography G

内存限制:256 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

The cows have formed a dance team, and Farmer John is their choreographer! The team's latest and greatest dance involves cows () standing in a line. Each move in the dance involves two cows, up to positions apart (), 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- binary strings, where a represents a Guernsey, a 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 and .

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

样例输入 2

5 2
11000
00011

样例输出 2

3

样例输入 3

5 4
11000
00011

样例输出 3

2

数据范围与提示

For Sample 1:

One possible dance:

0111 -> 1011 -> 1101 -> 1110
For Sample 2:

One possible dance:

11000 -> 01100 -> 00110 -> 00011
For Sample 3:

One possible dance:

11000 -> 10010 -> 00011

SCORING:

  • Inputs 4-5: .
  • Inputs 6-7: Both strings have at most ones.
  • Inputs 8-15: .
  • Inputs 16-23: No additional constraints.