eolymp
bolt
Try our new interface for solving problems
Problems

Chips Challenge

Chips Challenge

A prominent microprocessor company has enlisted your help to lay out some interchangeable components (widgets) on some of their computer chips. Each chip’s design is an \textbf{N}×\textbf{N} square of slots. One slot can hold a single component, and you are to try to fit in as many widgets as possible. Modern processor designs are complex, of course. You unfortunately have several restrictions: \begin{itemize} \item Some of the slots are disabled. \item Some of the slots are already occupied by other components and cannot be used for widgets. \item There are sibling memory buses connected to the horizontal and vertical edges of the chip and their bandwidth loads need to match. As such, there must be exactly as many components in the first row as in the first column, exactly as many in the second row as in the second column, and so on. Component counts include both the components already specified on the chip and the added widgets. \item Similarly, the power supply is connected at the end of each row and column. To avoid hot spots, any given row or column must have no more than \textbf{A/B} of the total components on the chip for a given \textbf{A} and \textbf{B}. \end{itemize} A specification for a chip is \textbf{N} lines of \textbf{N} characters, where '\textbf{.}' indicates an open slot, '\textbf{/}' indicates a disabled slot, and '\textbf{C}' indicates a slot already occupied by a component. For example: \textbf{CC/.. ./.// ..C.C /.C.. /./C/} If no more than \textbf{3/10} of the components may be in any one row or column, the maximum number of widgets that can be added to this \textbf{5}×\textbf{5} chip is \textbf{7}. A possible arrangement is below, where '\textbf{W}' indicates a widget added in an open slot. \textbf{CC/W. W/W// W.C.C /.CWW /W/C/} \InputFile The input consists of several test cases. Each case starts with a line containing three integers: The size of the chip \textbf{N} (\textbf{1} ≤ \textbf{N} ≤ \textbf{10}), and \textbf{A} and \textbf{B} (\textbf{1} ≤ \textbf{B} ≤ \textbf{1000}, \textbf{0} ≤ \textbf{A} ≤ \textbf{B}) as described above. Each of the following \textbf{N} lines contains \textbf{N} characters describing the slots, one of '\textbf{.}', '\textbf{/}' or '\textbf{C}', as described above. The last test case is followed by a line containing three zeros. \OutputFile For each test case, display a single line beginning with the case number. If there is a solution, display the maximum number of widgets that can be added to the chip. Display "\textbf{impossible}" if there is no solution. Follow the format of the sample output.
Time limit 30 seconds
Memory limit 256 MiB
Input example #1
2 1 1
/.
//
0 0 0
Output example #1
Case 1: 0
Source ICPC 2011 World Finals