[USACO24OPEN] Cowreography G

Luogu
IDLGP10280
Time2000ms
Memory256MB
DifficultyP5
数学贪心USACO2024
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! ## Input 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. ## Output The minimum number of moves in the dance. [samples] ## Note ##### For Sample 1: One possible dance: ```text 0111 -> 1011 -> 1101 -> 1110 ``` ##### For Sample 2: One possible dance: ```text 11000 -> 01100 -> 00110 -> 00011 ``` ##### For Sample 3: One possible dance: ```text 11000 -> 10010 -> 00011 ``` #### SCORING: - Inputs 4-5: $K=1$. - Inputs 6-7: Both strings have at most $8$ ones. - Inputs 8-15: $N\le 5000$. - Inputs 16-23: No additional constraints.
Samples
Input #1
4 1
0111
1110
Output #1
3
Input #2
5 2
11000
00011
Output #2
3
Input #3
5 4
11000
00011
Output #3
2
API Response (JSON)
{
  "problem": {
    "name": "[USACO24OPEN] Cowreography G",
    "description": {
      "content": "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 involv",
      "description_type": "Markdown"
    },
    "platform": "Luogu",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": {
      "LuoguStyle": "P5"
    },
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "LGP10280"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "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 involv...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments