2014 Mock CCC by Alex and Timothy
Alice's love for Bob is everlasting. Unfortunately, they are fated to be
apart in the current time. Alas, her burning love cannot be stopped by
such a small obstacle. To reach Bob, Alice has acquired a time machine
with .
, and obstacles (places where they may not
walk) are denoted by X
.
From Alice's perspective of time, it takes
Input Specification
The first line of input contains the integers
The following contains A
indicates Alice's current position and B
indicates Bob's current
position. It is guaranteed that Alice cannot reach Bob from traversing
only the present day setting.
Output Specification
The shortest time that it takes for Alice to reach Bob, in seconds from
Alice's perspective. If this is not possible, output -1
.
Sample Input 1
3 3 2
AXX
.X.
XXB
XXX
...
XXX
Sample Output 1
6
Explanation for Sample Output 1
There are two time settings, depicted below:
(Present Day)
Setting 0: Setting 1:
AXX XXX
.X. ...
XXB XXX
The best path Alice can take is:
Sample Input 2
2 5 3
BXXA.
XXX.X
.XXXX
..XXX
X...X
X.X.X
Sample Output 2
8
Explanation for Sample Output 2
The three time settings are:
(Present Day)
Setting 0: Setting 1: Setting 2:
BXXA. .XXXX X...X
XXX.X ..XXX X.X.X
The best path she can take is:
Comments