eolymp
bolt
Попробуйте наш новый интерфейс для отправки задач
Задачи

Frame Stacking

Frame Stacking

Consider the following \textbf{5} picture frames placed on an \textbf{9}×\textbf{8} array. \includegraphics{https://static.e-olymp.com/content/37/375c4d20078df48ffeaf3e74fe56ed9cf020b63d.jpg} Now place them on top of one another starting with \textbf{1} at the bottom and ending up with \textbf{5} on top. If any part of a frame covers another it hides that part of the frame below. Viewing the stack of \textbf{5} frames we see the following. \includegraphics{https://static.e-olymp.com/content/bf/bf9466811fdd1cd9d75b197900d71bb7b9c708fb.jpg} In what order are the frames stacked from bottom to top? The answer is \textbf{EDABC}. Your problem is to determine the order in which the frames are stacked from bottom to top given a picture of the stacked frames. Here are the rules: \begin{enumerate} \item The width of the frame is always exactly \textbf{1} character and the sides are never shorter than \textbf{3} characters. \item It is possible to see at least one part of each of the four sides of a frame. A corner shows two sides. \item The frames will be lettered with capital letters, and no two frames will be assigned the same letter. \end{enumerate} \InputFile Each input block contains the height, \textbf{h} (\textbf{h} ≤ \textbf{30}) on the first line and the width \textbf{w} (\textbf{w} ≤ \textbf{30}) on the second. A picture of the stacked frames is then given as \textbf{h} strings with \textbf{w} characters each. \OutputFile Write the solution to the standard output. Give the letters of the frames in the order they were stacked from bottom to top. If there are multiple possibilities for an ordering, list all such possibilities in alphabetical order, each one on a separate line. There will always be at least one legal ordering for each input block. List the output for all blocks in the input sequentially, without any blank lines (not even between blocks).
Лимит времени 1 секунда
Лимит использования памяти 64 MiB
Входные данные #1
9
8
.CCC....
ECBCBB..
DCBCDB..
DCCC.B..
D.B.ABAA
D.BBBB.A
DDDDAD.A
E...AAAA
EEEEEE..
Выходные данные #1
EDABC
Источник Southern African 2001