Time limit
2s
Memory limit
128 MB
A castle is represented as an M by N grid of square cells. Each side of a cell may have a wall, and you can move to an adjacent cell only through a side without a wall.
Given the map of the castle, compute these three values.
The area of a room is the number of cells in that room. The castle has at least two rooms, and there is always at least one wall whose removal merges two different rooms.
The first line contains two integers N and M. N is the number of columns, M is the number of rows, and 1 <= N, M <= 50.
Each of the next M lines contains N integers. Each integer describes the walls of one cell. Add 1 for a west wall, 2 for a north wall, 4 for an east wall, and 8 for a south wall. Therefore each value is between 0 and 15, inclusive.
Print the number of rooms in the castle on the first line. Print the area of the largest room on the second line. Print the largest room area obtainable by removing one wall on the third line.