Special Dropkick 2
Time limit1sMemory limit1024 MB
Given a corridor string with obstacles, push obstacles at most M times, then find the minimum seconds to walk from zone 0 to zone N, breaking obstacles for 2 seconds each.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Greedy, Prefix sum
- Solved
- No attempts yet
Problem
The buildings in NLCS Jeju are flimsy, so walls and doors can be broken with a dropkick.
The corridor of NLCS Jeju is divided into square zones numbered through . Each zone except zone , where Dongho stands, may contain an obstacle. Dongho wants to move from zone to zone , where the classroom is, as quickly as possible.
Dongho has a string of length that describes the corridor. For each integer , if is X, zone has an obstacle. If is ., zone has no obstacle.
Dongho can move obstacles at most times in the following ways.
- Push an obstacle one cell toward higher numbers. All consecutive obstacles in the direction of higher numbers move together.
- Push an obstacle one cell toward lower numbers. All consecutive obstacles in the direction of lower numbers move together.
After being pushed, the obstacles must still be within zones through .
After moving obstacles at most times, Dongho reaches the classroom by combining two techniques.
- Spend 1 second to move one zone toward higher numbers. Dongho cannot move into a zone that has an obstacle.
- Spend 2 seconds to destroy an obstacle next to Dongho. Dongho can also destroy obstacles adjacent to the destroyed one. After destroying obstacles, Dongho moves to the position of a destroyed obstacle. If several were destroyed, Dongho can move to any of those positions.
Dongho wants to minimize the time to reach the classroom. Find how many seconds it takes to reach the classroom.
Input
The first line contains and , separated by a space.
The second line contains the string of length that describes the corridor. If is X, zone has an obstacle. If is ., zone has no obstacle.
Output
Print the number of seconds it takes Dongho to reach the classroom, as an integer.