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

Bicube

Mary Thomas has a number of sheets of squared paper. Some of squares are painted either in black or some \textit{colorful} color (such as red and blue) on the front side. Cutting off the unpainted part, she will have eight opened-up unit cubes. A unit cube here refers to a cube of which each face consists of one square. She is going to build those eight unit cubes with the front side exposed and then a \textit{bicube} with them. A bicube is a cube of the size \textbf{2}×\textbf{2}×\textbf{2}, consisting of eight unit cubes, that satisfies the following conditions: \begin{itemize} \item faces of the unit cubes that comes to the inside of the bicube are all black; \item each face of the bicube has a uniform \textit{colorful} color; and \item the faces of the bicube have colors all different. \end{itemize} Your task is to write a program that reads the specification of a sheet of squared paper and decides whether a bicube can be built with the eight unit cubes resulting from it. \InputFile The input contains the specification of a sheet. The first line contains two integers \textbf{H} and \textbf{W}, which denote the height and width of the sheet (\textbf{3} ≤ \textbf{H}, \textbf{W} ≤ \textbf{50}). Then \textbf{H} lines follow, each consisting of \textbf{W} characters. These lines show the squares on the front side of the sheet. A character represents the color of a grid: alphabets and digits ('\textbf{A}' to '\textbf{Z}', '\textbf{a}' to '\textbf{z}', '\textbf{0}' to '\textbf{9}') for colorful squares, a hash ('\textbf{#}') for a black square, and a dot ('\textbf{.}') for an unpainted square. Each alphabet or digit denotes a unique color: squares have the same color if and only if they are represented by the same character. Each component of connected squares forms one opened-up cube. Squares are regarded as connected when they have a common edge; those just with a common vertex are not. \OutputFile Print "\textbf{Yes}" if a bicube can be built with the given sheet; "\textbf{No}" otherwise.
Лимит времени 1 секунда
Лимит использования памяти 64 MiB
Входные данные #1
3 40                                                             
.a....a....a....a....f....f....f....f...
#bc#.#cd#.#de#.#eb#.#cb#.#dc#.#ed#.#be#.
.#....#....#....#....#....#....#....#...
Выходные данные #1
Yes
Источник The 2011 35th Annual ACM Programming Contest Winter Camp