#P17896. [ICPC 2026 Nanchang I] Gotta Go Fast
[ICPC 2026 Nanchang I] Gotta Go Fast
Problem Description
Have you ever played Eggy Party? inf loves playing Eggy Party.
Four eggies are stacked into a four-story eggy tower, with the bottom initially at coordinate . From bottom to top, they are sequentially labeled A, B, C, and D, where D is the topmost eggy.
The total length of the track is , which consists of segments of length . Segment connects coordinates and .
The terrain of the -th segment is given by the character . If the eggy tower walks from coordinate to coordinate , the cost is:
- Flat ground
0: seconds; - Mud pit
1: seconds; - Speed pad
2: seconds.
The eggy tower can perform two types of operations:
- Normal Advance: If the current eggy tower is at coordinate , it can advance forward to coordinate . The time cost of this advance depends only on the terrain of segment .
- Super Start: If there is an eggy tower containing eggies at coordinate , the bottommost eggy can instantly throw the eggies above it to coordinate , where is a given positive integer. This operation does not trigger any terrain time cost, i.e., it takes seconds. After the operation, the bottommost eggy at the original position is eliminated, leaving that position empty; a new eggy tower containing eggies is formed at coordinate , and the vertical order of the remaining eggies stays the same.
Please compute the minimum time required for the initially topmost eggy D to reach the destination coordinate .
Input Format
The first line contains two positive integers and ().
The second line contains three positive integers , , ().
The third line contains a string of length , consisting only of the characters 0, 1, and 2.
Output Format
Output a single integer representing the minimum total time.
10 2
10 20 5
0000000000
40
12 3
10 100 1
111000222000
3
10 2
10 100 1
2220110000
13
8 3
10 100 1
00000000
0
Hint
For Example 1: One optimal strategy is to consecutively trigger Super Start times to reach coordinate , and then walk through the final flat ground segments. The total time cost is .
For Example 2: One optimal strategy is to first consecutively trigger Super Start twice to reach coordinate , walk through speed pads to reach coordinate , and finally trigger Super Start again to reach the destination. The total time cost is .
For Example 3: One optimal strategy is to first walk through the first speed pads and flat ground segment to reach coordinate , and then consecutively trigger Super Start times to reach the destination. The total time cost is .
For Example 4: Consecutively trigger Super Start times. The coordinate changes as (the last time triggers the limit). Walking is not needed throughout the process, and the total time cost is .