|
Umika |
What do you think you're doing!!!!! |
|
Arata |
Isn't it obvious?! We, the Mouryo, are taking back the Shimmoku Festival! |
|
Arata |
The Shimmoku Festival only happens once a year. It is a festival to pray for peace and well-being in Hyakkiyako... |
|
Arata |
And at a festival like that! I don't want outsiders from Gehenna Academy barging in, even if they were invited! |
|
Tsubaki |
...What exactly are you planning to do? |
|
Arata |
Heeheehee... Try not to be too shocked. I have devised a plan so terrifying, meticulous, and magnificent that even a crying child would fall silent in awe... |
The first line contains a positive integer , the size of the plaza.
The next lines each contain a string of length describing the plaza. A character indicates Umika's cell, indicates Arata's cell, indicates an obstacle, and indicates an empty cell.
On the first line, print the minimum rope length needed to catch Arata.
On the second line, print the minimum total force needed to retrieve a rope of that minimum length.
|
Arata |
And that plan is! |
|
Arata |
Those enormous fireworks meant for the evening display! The grand climax of the Shimmoku Festival...! |
|
Arata |
We're setting them all off! In broad daylight! |
|
Umika |
Absolutely not! I will not allow it, Mouryo! |
|
Umika |
For the students of Gehenna Academy, and for Sensei... I will protect the Shimmoku Festival! |
|
Umika |
I will never, ever let you lay a finger on those fireworks! |
|
Pina |
C-calm yourself, Umika! |
|
Kaede |
U-um, wait. Is this okay? Can we really start a big ruckus here? At the Shimmoku Festival? In the plaza? |
|
Tsubaki |
...Sometimes we have to act. Otherwise... something even worse will happen. |
Sensei! We have to stop Arata and the Mouryo before they ruin the Shimmoku Festival! Fighting here might set the fireworks alight... so I want to catch Arata with a rope, with help from the Inner Discipline Club.
The plaza is an grid. I am at the center of the cell in row , column , and Arata is at the center of some cell in the plaza. With the students helping me, we can lay the rope by moving from the center of one cell to the center of another. The Inner Discipline Club students may move only to adjacent cells above, below, to the left, or to the right.
Suppose the Inner Discipline Club students start at row , column , and visit a total of cells , , , in order.
We define the length of the rope as the number of line segments it consists of, namely .
Once we catch Arata with the rope, I have to pull it back in immediately. But the more bends there are, the more the rope catches and resists being pulled, requiring greater force. If it takes too much force, retrieving it will take longer, and Arata might escape or things might become more dangerous in the meantime. So I need to minimize the total force, too.
When the rope currently consists of points , , , , pulling it once does the following.
The endpoint is removed, leaving only the points , , , to form the rope.
I must repeat this process to retrieve the entire rope, pulling until only point remains.
We need to catch Arata as quickly as possible, before the Mouryo do anything else. So I will first minimize the length of the rope used to catch her, and among ropes of that minimum length, minimize the total force required to retrieve the entire rope. We need to find how the Inner Discipline Club students should move to minimize these two values. Sensei, will you help me?
UA#.Umika appears only in row , column , and there is exactly one cell containing Arata.
It is guaranteed that Arata can be caught.
This retrieval step requires an amount of force equal to the number of bends in the rope immediately before it is pulled.