Bulbs
Time limit1sMemory limit128 MB
Given a target 2×N binary grid, find the minimum number of toggle operations on contiguous row or column segments to reach that pattern.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Greedy, Matrix
- Solved
- No attempts yet
Problem
2×N bulbs are arranged in two rows. Each row has N bulbs, and initially every bulb is off.
Hyunsu wants to create a desired beautiful pattern in several operations. In one operation, he chooses one or more consecutive bulbs in a single row or a single column, then toggles all chosen bulbs. An off bulb becomes on, and an on bulb becomes off.
Given the target pattern, determine the minimum number of operations needed to create it.
Input
The first line contains the number of columns N. (1 ≤ N ≤ 10,000)
The next two lines describe the pattern Hyunsu wants to create. 1 means the bulb is on, and 0 means the bulb is off.
Output
Output the minimum number of operations needed to create the desired pattern.