33OJ
登录 注册

#P17896. [ICPC 2026 Nanchang I] Gotta Go Fast

    ID: 20632 远端评测题 1000ms 1024MiB 尝试: 0 已通过: 0 显示难度普及− 上传者: 标签>动态规划 DP江西ICPC2026省赛/邀请赛

[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 00. 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 ll, which consists of ll segments of length 11. Segment ii connects coordinates i−1i-1 and ii (1≤i≤l)(1 \le i \le l).

The terrain of the ii-th segment is given by the character SiS_i. If the eggy tower walks from coordinate i−1i-1 to coordinate ii, the cost is:

  • Flat ground 0: t0t_0 seconds;
  • Mud pit 1: t1t_1 seconds;
  • Speed pad 2: t2t_2 seconds.

The eggy tower can perform two types of operations:

  • Normal Advance: If the current eggy tower is at coordinate x<lx < l, it can advance forward to coordinate x+1x+1. The time cost of this advance depends only on the terrain of segment x+1x+1.
  • Super Start: If there is an eggy tower containing jj eggies at coordinate xx (j≥2)(j \ge 2), the bottommost eggy can instantly throw the j−1j-1 eggies above it to coordinate min⁡(l,x+d)\min(l, x+d), where dd is a given positive integer. This operation does not trigger any terrain time cost, i.e., it takes 00 seconds. After the operation, the bottommost eggy at the original position is eliminated, leaving that position empty; a new eggy tower containing j−1j-1 eggies is formed at coordinate min⁡(l,x+d)\min(l, x+d), 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 ll.

Input Format

The first line contains two positive integers ll and dd (1≤d<l≤2×1051 \le d < l \le 2 \times 10^5).

The second line contains three positive integers t0t_0, t1t_1, t2t_2 (1≤t2<t0<t1≤1091 \le t_2 < t_0 < t_1 \le 10^9).

The third line contains a string SS of length ll, 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 33 times to reach coordinate 66, and then walk through the final 44 flat ground segments. The total time cost is 4×10=404 \times 10 = 40.

For Example 2: One optimal strategy is to first consecutively trigger Super Start twice to reach coordinate 66, walk through 33 speed pads to reach coordinate 99, and finally trigger Super Start again to reach the destination. The total time cost is 1+1+1=31+1+1=3.

For Example 3: One optimal strategy is to first walk through the first 33 speed pads and 11 flat ground segment to reach coordinate 44, and then consecutively trigger Super Start 33 times to reach the destination. The total time cost is 1+1+1+10=131+1+1+10=13.

For Example 4: Consecutively trigger Super Start 33 times. The coordinate changes as 0→3→6→80\to 3\to 6\to 8 (the last time triggers the min⁡(8,6+3)\min (8, 6+3) limit). Walking is not needed throughout the process, and the total time cost is 00.