Logo
(追記) (追記ここまで)

21198번 - Arithmetic Decoding 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB29262592.593%

문제

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

The current interval $[a,b)$ is initially set to $[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 + p_A(b-a)$. If the next letter is 'A', $[a,c)$ becomes the current interval. Otherwise, the current interval is now $[c,b)$. This process is repeated for each letter in the message. If $[k,\ell)$ is the final interval, the encoded message is chosen to be $k$.

For example, if the original message is "ABAB" and $p_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 $N$ (1ドル \leq N \leq 15$), which is the length of the original message. The second line contains the integer $D$ (1ドル \leq D \leq 7$), which indicates that $p_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 3ドルN+2$ characters.

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

출력

Display the original message.

제한

예제 입력 1

4
4
0.0101

예제 출력 1

ABAB

예제 입력 2

6
5
0.100100100100101

예제 출력 2

ABBABA

힌트

출처

ICPC > Regionals > North America > Rocky Mountain Regional > 2020 Rocky Mountain Regional Contest B번

  • 문제를 만든 사람: Howard Cheng
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /