407228: GYM102697 199 Plane Tour
Description
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.
InputThe 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.
OutputOutput a single positive integer $$$p$$$: the maximum number of aircraft that you can see on your facility tour, only visiting one room.
ExamplesInput5 5 P.X.. ..XP. XXXX. ...XP ...X.Output
2Input
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 XXXXXXXXXXOutput
4