| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 2 초 (추가 시간 없음) | 2048 MB | 32 | 15 | 13 | 68.421% |
Morse code is a classical way to communicate over long distances, but there are some drawbacks that increase the transmission time of long messages.
In Morse code, each character in the alphabet is assigned a sequence of dots and dashes such that no sequence is a prefix of another. To transmit a string of characters, the sequences corresponding to each character are sent in order. A dash takes twice as long to transmit as a dot.
Your alphabet has $n$ characters, where the $i$-th character appears with frequency $f_i$ in your language. Your task is to design a Morse code encoding scheme, assigning a sequence of dots and dashes to each character, that minimizes the expected transmission time for a single character. In other words, you want to minimize $f_1t_1 + f_2t_2 + \cdots + f_nt_n,ドル where $t_i$ is the time required to transmit the sequence of dots and dashes assigned to the $i$-th character.
The first line contains an integer $n$ (2ドル ≤ n ≤ 200$) — the number of characters in the alphabet.
The second line contains $n$ real numbers $f_1, f_2, \dots , f_n$ (0ドル < f_i < 1$) — $f_i$ is the frequency of the $i$-th character. All values $f_1, f_2, \dots , f_n$ are given with exactly four digits after the decimal point. The sum of all frequencies is exactly 1ドル$.
Print $n$ lines, each containing one string consisting of dots . and dashes -. The $i$-th line corresponds to the sequence of dots and dashes that you assign to the $i$-th character.
If there are multiple valid assignments with the minimum possible expected transmission time, any of them is considered correct.
3 0.3000 0.6000 0.1000
-. . --
The alphabet contains three letters, say $a,ドル $b,ドル and $c,ドル with respective frequencies 0ドル.3,ドル 0ドル.6,ドル and 0ドル.1$. In the optimal assignment, we assign $a$ to ‘-.’, $b$ to ‘.’, and $c$ to ‘-’. This gives an expected transmission time of 0ドル.3 \cdot 3 + 0.6 \cdot 1 + 0.1 \cdot 4 = 1.9$ time units per character, which is optimal.
For comparison, the assignment $a$ → ‘..’, $b$ → ‘-’, $c$ → ‘.-’ has an expected transmission time of 0ドル.3 \cdot 2 + 0.6 \cdot 2 + 0.1 \cdot 3 = 2.1$. The assignment $a$ → ‘-’, $b$ → ‘.’, $c$ → ‘..’ has a lower expected transmission time, but is invalid since ‘.’ is a prefix of ‘..’.
3 0.3000 0.4500 0.2500
.. - .-