#P12396. Optimizing Basketball Training Sequence

    ID: 14499 Type: Default 1000ms 256MiB

Optimizing Basketball Training Sequence

Optimizing Basketball Training Sequence

B City has a basketball exam with the following rules:

  • A complete group of actions consists of: dribbling from the three‐point line to under the basket, then performing a layup action (which must be successful) and finally returning to the three-point line.
  • The layup action is performed while the candidate is under the basket. In one continuous period under the basket only shooting actions occur. A shooting action can be either an aimed layup (denoted by A) or a random layup (denoted by W). An aimed layup always scores and takes \( b \) seconds, while a random layup always misses and takes \( c \) seconds. However, if the candidate misses three consecutive random layups (i.e. three W actions in a row) then the layup is also deemed successful.
  • The dribbling actions from the three‐point line to the basket (G) and back (B) both take \( a \) seconds. The candidate starts at the three–point line, and a complete group is expected to be performed as: G (dribble to basket), one or more shooting actions that yield a successful layup (by either one A or a combination of W actions, where three consecutive misses count as success) and then a B (dribble back to three–point line).
  • The candidate must complete at least 4 complete groups and finish at the three–point line. The total time is the sum of the time of all actions (both previously performed and the ones you will plan).
  • If the total time is no more than 35 seconds, the candidate scores full marks; if it exceeds 45 seconds, the score is zero. (However, your task is to plan the remaining actions such that the overall time is minimized.)

During training, the candidate (Qingfeng) can perform the following actions:

  • If he is at the three–point line, he may dribble to the basket (operation G), which takes \( a \) seconds and moves him to the basket.
  • If he is at the basket, he may dribble back (operation B), which takes \( a \) seconds and moves him to the three–point line.
  • If he is at the basket, he may attempt a layup by either an aimed layup (operation A, taking \( b \) seconds and always scoring) or a random layup (operation W, taking \( c \) seconds and always missing).

You are given a legal sequence of operations that Qingfeng has already performed in a training session. Please help him plan the remaining operations so that he completes the exam (i.e. completes at least 4 full groups ending at the three–point line) and his overall time (the sum of the durations of all operations, including those already executed) is minimized.

Note: For a partially completed group at the basket, you can choose to finish the shooting phase in one of two ways: either perform an aimed layup (A) to immediately secure success or continue with random layups (W) until 3 consecutive misses are accumulated (each miss taking \( c \) seconds). Once a successful layup is attained, a dribble back (B) must be executed to complete the group. For a new full group starting from the three–point line, the optimal sequence is G + (optimal shooting action) + B.
The optimal shooting action is determined by comparing the time cost of a single aimed layup (\( b \)) and three random layups (\( 3c \)).

inputFormat

The input consists of two lines:

  1. The first line contains three integers \( a \), \( b \), and \( c \) separated by spaces.
  2. The second line contains a non-empty string representing the sequence of operations that Qingfeng has already performed. The operations are characters from the set {G, A, W, B} and the sequence is guaranteed to be legal.

outputFormat

Output a string representing the sequence of operations that Qingfeng should perform next (appended to the already performed operations) so that he completes the exam with the minimum extra time.

sample

1 2 3
GABG
ABGABGAB