407228: GYM102697 199 Plane Tour

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

199. Plane Tourtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output
This problem is worth 65 points.

Your team solved all of the problems at CodeQuest 2021, and as a reward, the supervisors of the competition decided to show your team a room full of new aircraft (CodeQuest is run by Lockheed Martin, which builds airplanes and helicopters at their Owego, NY site, which the CodeRams attend every year).

Once your team is dropped off in a room, the CodeQuest supervisors will let your team travel around the room and look at all of the new airplanes and helicopters. However, there are different rooms, and some of them are separated by impassable walls and locked doors.

Since your team performed so well in the CodeQuest competition, the supervisors let your team choose which room to tour. You can only go in one room during the tour.

Your task is to figure out the maximum number of aircraft that you can see, if you visit the optimal room on your team's private tour.

Input

The Lockheed Martin facility that the competition is taking place at can be represented as a 2D grid.

The first line of input contains two space-separated integers $$$n$$$ and $$$m$$$: the number of rows and columns of the grid representation of the facility, respectively.

The next $$$n$$$ lines each contain $$$m$$$ characters: the 2D top-down view representation of the Lockheed Martin facility.

If a character is a single dot ("."), then the space in the grid is empty space that can be walked through. If a character is an x ("X"), then the space in the grid is an impassable wall. If a character is a p ("P"), then the space in the grid is an airplane or helicopter. Note that you can walk through a space with an aircraft.

You cannot walk diagonally.

Output

Output a single positive integer $$$p$$$: the maximum number of aircraft that you can see on your facility tour, only visiting one room.

ExamplesInput
5 5
P.X..
..XP.
XXXX.
...XP
...X.
Output
2
Input
11 10
XXXXXXXXXX
X..P.....X
X.XXX....X
X...X....X
X...XX...X
X.X.PX.P.X
X.XXXX...X
X....PXXXX
XXXXXX.P.X
XPPP.X.PPX
XXXXXXXXXX
Output
4

加入题单

上一题 下一题 算法标签: