A Freshman Needs Friends
InterviewTime limit1sMemory limit1024 MB
Given an N by M grid with walls, Doyeon's start cell, and people, count how many people are reachable from her by moving up, down, left, or right.
Problem
Doyeon is a freshman who entered university in 2020. Because of remote classes she could not go to campus, so she had no friends there. Now that in-person classes have finally begun, she wants to get close to the people on campus as soon as possible.
The campus of Doyeon's university is in size, and movement on campus is up, down, left, or right onto a cell that is not a wall. For example, if Doyeon is at (, ), she can move to (, ), (, ), (, ), or (, ). She cannot move outside the campus.
For poor Doyeon, write a program that prints the number of people she can meet on campus.
Input
The first line gives two integers () and (), the size of the campus.
From the second line, lines give the campus information. O is an empty space, X is a wall, I is Doyeon, and P is a person. It is guaranteed that I is given exactly once.
Output
On the first line, print the number of people Doyeon can meet. If she meets nobody, print TT.