Cowntact Tracing 2
InterviewTime limit2sMemory limit1024 MB
Find the fewest starting infected cows that, spreading to adjacent cows each night, produce the given infected bitstring.
- Level
Medium5 of 10
- Topics
- Greedy, Dynamic programming, String
- Solved
- No attempts yet
Problem
Farmer John has cows in a line (). Unfortunately, a sickness is spreading through the herd.
Initially, some cows are infected. Every night, each infected cow spreads the sickness to the cows on its left and right (if they exist). Once a cow is infected, it stays infected.
After some number of nights, Farmer John realizes the problem has gotten out of control, so he tests his cows to see which ones have the sickness. Find the minimum number of cows that could have been infected at the start.
Input
The first line contains , the number of cows.
The next line contains a bitstring of length consisting only of 1 and 0. A 1 means the cow is infected after some number of nights, and a 0 means it is not.
Output
Output a single integer: the minimum number of cows that could have been infected at the start.