Berry Battle 2
시간 제한8초메모리 제한1024 MB
길이 10만인 무작위 문자열에서 절반이 'b'일 때, 항상 가장 많은 열매를 주는 네 칸 구간을 고르는 할아버지보다 적지 않게 딴 열매를 얻도록 에릭의 수를 정하는 문제다.
문제
Erik and his grandpa often go to the forest to pick blueberries. Grandpa always finds the most berries, and even though it is not a competition, Erik has had enough of this. He has observed that grandpa uses a simple greedy strategy to pick as many berries as possible. With this information, Erik will try to finally pick at least as many berries as grandpa.
The blueberry shrubs can be represented as a string of length , consisting of characters . and b. If b, then there is a berry at position , otherwise there is no berry there. There will be exactly berries to start with, and they are distributed uniformly at random.
The berry picking takes place in turns. In one move, a person can choose a position (), and pick all the berries at positions , , , and . Grandpa makes the first move, then Erik makes a move, then grandpa, and so on. Grandpa will always greedily make a move that picks as many berries as possible. Among all such moves, he will pick one uniformly at random.
You are given the string , and your task is to write a program that decides what moves Erik should make in order to pick at least as many berries as grandpa.