G |
Power
Faster Input: Standard Input Output: Standard Output |
This is Power
Faster. In future, this is going the primary study material for the children of
primary schools in
The flat rectangular part to the front is the display unit. And LDC screen
consisting of pixel arranged in a regular grid of R rows and C
collumns along with a display adaptar comprises the display unit. The LDC
screen has some special properties making it power efficient in an unusual way.
It consumes least power when exactly 50% of its pixels are turned ON and the
rest are OFF. For any other number of ON and OFF pixels, the power consumption
increases linearly upto the point of maximum consumption which occurs when
either all pixels are turned ON or all are turend OFF.
The display adapter gets a bitmap image with dimensions r x c, let us call
it the input image, which has to be shown on the screen. To minimize the power
consumption, display adapter scales the image in horizontal and vertical
directions by integer scaling factors such that the dimensions of the scaled
input image do not exceed that of the display screen. The scaling factors in
horizontal and vertical direction are independent.
The scaling process is analogous to enlarging a photograph. When scaled by a horizontal and vertical scaling factor of hs and vs respectively, the result is an image of r*vs rows and c*hs columns. Each pixel in the input images corresponds to a rectangle of vs rows and hs columns in the resulting image. Note that, however tempting it might seem, the display adapter does not perform any kind of rotation.
You are asked to write a program performing the scaling for the display adapter.
Input will consist of multiple test case. Each test case starts with a line containing 4 positive integers R C r c seperated by whitespace. Next r lines, each having c characters on it, comprises the input image. The input image is drawn using '.' (dot) and '#' (hash) characters and there will be no other character in the input image. You can also assume that, R >= C, r>=c and all numbers are positive integers smaller than 30000.
There will be 1005 such test cases.
Print one line of output for each test case. The output of each case starts with the case number written as “Case n: ” (excluding the quote marks) as shown in the sample output followed by two integers. The first integer will be the scaling factor in horizontal direction, second integer should be the scaling factor in vertical direction.
If more than one possible way to achieve minimum power consumption exists, output the one with largest horizontal scaling factor. If there are still multiple solutions, output the one with smallest vertical scaling factor. All numbers should be positive integers.
50 25 8 4 #### #..# #..# #..# #..# #..# #..# #### 2 2 1 1 # |
Case 1: 6 5 Case 2: 2 1 |
Problem setter: Raiyan Kamal, Special Thanks: Sabbir Yousuf Sanny