Answered step by step
Verified Expert Solution
Question
1 Approved Answer
pythone code E. Swans time limit per test: 2 seconds 0 memory limit per test: 1024 megabytes input: standard input output: standard output Yi and
pythone code
E. Swans time limit per test: 2 seconds 0 memory limit per test: 1024 megabytes input: standard input output: standard output Yi and Han are two swans living on a lake. They are good friends and often play together. One day they woke up and found out that because of the snow last night, they were separate in two different areas by ice. The lake can be viewed as a rc grid. We will use " X " to represent a cell of ice, and "." a cell as water. At the beginning, Yi and Han are both at a cell of water. Every day, some ice cells " X " will melt. An ice cell " X " melts if and only if in the previous day, at least one of its adjacent grids is water. Here "adjacent" means on the top, bottom, left and right, at most 4 of them. An example of the ice melting process is shown above. Yi and Han can both swim to any adjacent water cell from their current position, but they cannot swim to any ice cells. They both swim very fast so that they can arrive at any cell on the lake instantly as long as two cells are connected with water cells. Given the initial position of Yi and Han, and the current status of the lake, decide that at which day Yi and Han can meet again. Input The first line contains two integers r and c,1r,c1500. The following r lines each contains c characters, which describes the initial status of the lake. "." means a water cell. " X " means an ice cell. " L " means a swan. Output The output only contains one integer t, which means that after t days, Yi and Han can meetStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started