Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Farmer John has N cows in a line ) N ( 3 * 1 0 5 . Unfortunately, there is a sickness spreading throughout. Initially,
Farmer John has cows in a line Unfortunately, there is a sickness spreading throughout.
Initially, some cows start off infected. Every night, an infected cow spreads the sickness to the cows on their left and right if they exist Once a cow is infected, she stays infected.
After some amount of nights, Farmer John realizes that the issue has gotten out of control, so he tests his cows to determine who has the sickness. Find the minimum number of cows that could have started with the sickness.
INPUT FORMAT pipe stdin:
The first line contains the number of cows that Farmer John has.
The next line contains an character bitstring of only s and s where a represents an infected cow and a represents an uninfected cow after some number of nights.
OUTPUT FORMAT pipe stdout:
Output a single integer: the minimum number of cows that could have started with the sickness.
SAMPLE INPUT:
SAMPLE OUTPUT:
Suppose the middle cow was the only cow to start off infected. Then the cows would be infected in the following order:
nights: the third cow is initially infected
night: the second and four th cows are now infected
nights: the first and fifth cows are now infected
nights: all cows already were infected, so no additional cows are infected
dots
After two or more nights, the final state of the cows would look like the input. There are many other initial states and number of nights that could have produced the input state, such as:
nights:
night:
nights:
or:
nights:
night:
or:
nights:
night:
nights:
nights:
All of these initial states contain at least one infected cow.
SAMPLE INPUT:
SAMPLE OUTPUT:
The only initial state and number of nights that could have led to this final state is if no nights have passed and each of the four infected cows in the input started off with the sickness.
SCORING:
Inputs :
Inputs : No additional constraints.
Problem credits: Suhas Nagar
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started