Computers and Technology
Computers and Technology, 21.04.2020 04:51, mandyO1

A terrible new disease, HORSEVID, has begun to spread among horses worldwide. Stable manager Jimmy is trying to take as many precautions as possible to protect his herd from infection.

Stable manager Jimmy's barn is a long narrow building containing N stalls in a row (2≤N≤105). Some of these stalls are currently occupied by horses, and some are vacant. Having read about the importance of "social distancing", Stable manager Jimmy wants to maximize D, where D is the distance between the closest two occupied stalls. For example, if stalls 3 and 8 are the closest that are occupied, then D=5.

Two new horses recently joined Jimmy's herd and he needs to decide to which formerly-unoccupied stalls they should be assigned. Please determine how he can place his two new horses so that the resulting value of D is still as large as possible. Stable manager Jimmy cannot move any of his existing horses; he only wants to assign stalls to the new horses.

INPUT:

The first line of input contains N.

The next line contains a string of length N of 0s and 1s describing the sequence of stalls in the barn. 0s indicate empty stalls and 1s indicate occupied stalls. The string has at least two 0s, so there is at least enough room for two new horses.

OUTPUT:

Please print the largest value of D

(the closest distance between two occupied stalls) that Stable manager Jimmy can achieve after adding his two new horses in an optimal fashion.

SAMPLE INPUT:

14
10001001000010

SAMPLE OUTPUT:
2
In this example, Stable manager Jimmy could add horses to make the occupancy string look like 10x010010x0010, where x's indicate the new horses. In this case D=2. It is impossible to add the new horses to achieve any higher value of D.

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 01:10, shimmerandshine1
When you reach a yield sign, yield to cross traffic and before you enter the intersection. a. flash your headlights b. wait for a signal c. wait five seconds d. wait for a safe gap
Answers: 1
image
Computers and Technology, 23.06.2019 23:30, jamalchris9353
Worth 50 points answer them bc i am not sure if i am wrong
Answers: 1
image
Computers and Technology, 24.06.2019 18:30, trevorhenyan51
Dereck works for long hours on his computer.  he frequently experiences physical strain by the end of the day because he does not follow an important rule of ergonomics with respect to the use of keyboards.  which of the following actions of dereck could lead to physical strain? a.  placing the keyboard exactly in front of him while typingb.  keeping hands and wrists straight while typingc.  using wrist pads throughout the dayd.  pounding at the keys on the keyboard while typinge.  resting his hands on the keyboard when he is not typing
Answers: 1
image
Computers and Technology, 24.06.2019 20:20, jdkrisdaimcc11
Write python code that prompts the user to enter his or her age and assigns the user’s input to an integer variable named age.
Answers: 1
Do you know the correct answer?
A terrible new disease, HORSEVID, has begun to spread among horses worldwide. Stable manager Jimmy i...

Questions in other subjects: