#P9952. [USACO20OPEN] Social Distancing I B
[USACO20OPEN] Social Distancing I B
Problem Description
A new disease, COWVID-19, has begun spreading among cows around the world. Farmer John is taking as many precautions as possible to prevent his herd from being infected.
Farmer John's barn is a long, narrow building with a row of stalls (). Some stalls currently contain cows, and some are currently empty. Knowing the importance of "social distancing", Farmer John wants to make as large as possible, where is the distance between the two closest occupied stalls. For example, if stalls and are the closest occupied stalls, then .
Two new cows have just arrived in Farmer John's herd, and he needs to decide which two previously empty stalls to assign them to. Please determine how to place these two new cows so that is still as large as possible. Farmer John cannot move any existing cows; he only wants to assign stalls to the new cows.
Input Format
The first line of input contains . The next line contains a string of length consisting of and , describing the stalls in the barn. means an empty stall, and means an occupied stall. The string contains at least two characters, so there is enough space to place the two new cows.
Output Format
Output the maximum value of (the distance between the closest occupied stalls) that Farmer John can achieve after adding the two new cows in the optimal way.
14
10001001000010
2
Hint
Sample Explanation 1
In this example, Farmer John can add cows so that the stall assignment becomes 10x010010x0010, where x represents a new cow. Then . It is not possible to achieve a larger value of after adding the cows.
Test Point Properties
- Test points satisfy .
- Test points satisfy .
- Test points satisfy .
- Test points have no additional constraints.
Translated by ChatGPT 5