#t451. 城堡
城堡
The Castle
Problem Background
Special for beginners, ^_^
Problem Description
A castle is divided into an grid of cells (). Each cell may have to walls ( means no wall). The floor plan is shown below:

The thick black lines in the picture are walls. Several connected cells form a room, and rooms are always separated from each other by black lines (walls).
Write a program that answers these two questions:
- How many rooms are there in the castle?
- What is the area (number of cells) of the largest room?
Input Format
Each cell of the plan is described by a single number (the first cell, for example, is represented in binary as 1011, meaning "no east wall", which is decimal 11).
The first line contains one integer (): the length of the castle from south to north.
The second line contains one integer (): the length from east to west.
The following lines each contain integers, describing the cells of the plan row by row. The walls of a cell are encoded by a number (), which is the sum of the following values:
- — west wall
- — north wall
- — east wall
- — south wall
Interior walls are defined twice: for example, the south wall of cell is also defined once by cell to its south.
There are at least two rooms in the castle.
Output Format
The first line: one integer, the total number of rooms.
The second line: one integer, the area (number of cells) of the largest room.
Sample Input
4
7
11 6 11 6 3 10 6
7 9 6 13 5 15 5
1 10 12 7 13 7 5
13 11 10 8 10 12 13
Sample Output
5
9
Constraints
.
Time limit s, memory KiB per test case.
Hint
- Flood-fill each connected region: start from an unvisited cell, traverse through all cells reachable without crossing a wall, and mark them as one room.
- To test whether you can move from a cell in a given direction, check the corresponding bit of (and its neighbour's bit for shared walls).