409764: GYM103736 E Easy Problem
Memory Limit:512 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
E. Easy Problemtime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard output
Now you have an $$$n \times n$$$ map. It contains obstacles '$$$*$$$', space '$$$.$$$', playerA '$$$a$$$', playerB '$$$b$$$'.
You can control two players to move up, down, left or right at the same time. For example, now $$$A$$$ and $$$B$$$ are in $$$(x_a,y_a)$$$ and $$$(x_b, y_b)$$$, next time the two players can go to:
- $$$(x_a, y_a+1)$$$ and $$$(x_b, y_b+1)$$$
- $$$(x_a, y_a-1)$$$ and $$$(x_b, y_b-1)$$$
- $$$(x_a+1, y_a)$$$ and $$$(x_b+1, y_b)$$$
- $$$(x_a-1, y_a)$$$ and $$$(x_b-1, y_b)$$$
Note that if the next location is a boundary or obstacle the player will not move.
You need to find the minimum number of steps when two players can meet.
InputThe first line contains one integer $$$n$$$ $$$(2\leq n \leq 50)$$$.
For the next $$$n$$$ lines, each line contains a string of length $$$n$$$.
OutputIf in any case, the two players do not meet, print "no solution" in one line.
Otherwise, output the minimum number of steps.
ExamplesInput6 .a.... *..... ...... ..b*.. ..**.. ......Output
4Input
4 a*.. *... .... ...bOutput
no solutionInput
4 .ab. .... .... ....Output
2Input
7 ..a.b.. ....... ....... ....... ....... ....... .......Output
4