Author: | A. Klenin | Time limit: | 1 sec | |
Input file: | input.txt | Memory limit: | 256 Mb | |
Output file: | output.txt |
Eccentric millionaire Vasiliy Vorotkin-Tretij has a garden.
The garden is a rectangular area extending W meters from east to west and H meters from north to east. Each 1 × 1 meter square is either covered with walkable grass (represented by '.' character, ASCII 46) or by impenetrable bushes (represented by '#' character, ASCII 35).
A set of grass squares is a secluded area if:
Mystery level of garden is the number of secluded areas within it.
Vasiliy is quite proud of his garden's mystery level, and has decided to improve it. For this, he wants to build an additional wall of bushes from north to south across all the garden (i.e. replace all grass squares in a single column by bush squares).
Your program must find a location for a north-south wall which maximizes mystery level. In the second sample, original garden has mystery level 1. Replacing all grass squares in the 4th column by bushes will create five secluded areas, shown by digits in a picture. | 111#2# #1##2# 3#4#2# 3##### 333#55 |
First line of input file contains integers W H. Following H lines contain W characters each — garden representation.
Output file must contain two integers: maximum possible mystery level and number of column to be replaced by a wall (columns are numbered left to right from 1 to W).
If there are several optimal solutions, output one with the minimum column number.
1 ≤ W, H ≤ 1000
No. | Input file (input.txt ) |
Output file (output.txt ) |
---|---|---|
1 |
|
|
2 |
|
|
3 |
|
|