PivotOJ

Arithmetic Decoding

시간 제한: 1000ms메모리 제한: 1024MB출처: ICPC Rocky Mountain Regional 2020BOJ 21198

문제

Arithmetic coding is a method to represent a message as a real number xx such that 0x<10 \leq x < 1. We will assume that the message consists only of uppercase 'A's and 'B's.  The two letters have associated probabilities pAp_A and pB=1pAp_B = 1 - p_A such that 0<pA<10 < p_A < 1.

The current interval [a,b)[a,b) is initially set to [0,1)[0,1) and we will update this interval one letter at a time.  To encode a letter, the current interval is divided into two subintervals as follows.  Let c=a+pA(ba)c = a + p_A(b-a).  If the next letter is 'A', [a,c)[a,c) becomes the current interval.  Otherwise, the current interval is now [c,b)[c,b).  This process is repeated for each letter in the message.  If [k,)[k,\ell) is the final interval, the encoded message is chosen to be kk.

For example, if the original message is "ABAB" and pA=pB=0.5p_A = p_B = 0.5, the sequence of intervals encountered in the algorithm is \[ [0,1) \xrightarrow{A} [0, 0.5) \xrightarrow{B} [0.25, 0.5) \xrightarrow{A} [0.25, 0.375) \xrightarrow{B} [0.3125, 0.375). \] The encoded message is therefore 0.3125, or 0.0101 in binary.

Given the length of the message, the probabilities, and the encoded message, determine the original message.

입력

The first line contains the integer NN (1N151 \leq N \leq 15), which is the length of the original message.  The second line contains the integer DD (1D71 \leq D \leq 7), which indicates that pA=D8p_A = \frac{D}{8}. The third line contains the binary representation of the encoded message. It is guaranteed that the binary representation of the encoded message starts with "0." and contains at most 3N+23N+2 characters.

It is guaranteed that the encoded message came from an initial message of length NN consisting only of 'A' and 'B' using this value of pAp_A.

출력

Display the original message.

예제

예제 1

입력
4
4
0.0101
출력
ABAB

예제 2

입력
6
5
0.100100100100101
출력
ABBABA
코드를 제출하려면 로그인하세요.