Woburn Challenge 2018-19 Finals Round - Senior Division
Two particularly famous actors are starring in the cows' and monkeys' production: Tom Cows and Monkey Freeman. With both of them playing equally important roles, one question is at the forefront of everybody's mind: which of them will receive top billing in the credits and get to be the main face of the movie?
Tom isn't one to stand for playing second fiddle, so he's hatching a plan to discredit Monkey in the eyes of the director, Bo Vine. He's going to sneak into the main studio building in the middle of the night and rearrange its layout, in the hopes of causing Monkey to be late for the following morning's filming session. That'll show him!
The building can be represented as a grid with rows and columns . Note that the grid has at least as many rows as it has columns. Tom will choose one starting cell (leading to the parking lot) and one different ending cell (leading to the movie set). These cells may be anywhere in the grid (not necessarily on its edges). For each remaining cell in the grid, he'll choose to either leave it vacant or obstruct it with a wall. He'll make sure that it's possible to reach the ending cell from the starting one through a sequence of horizontally/vertically adjacent vacant cells.
In the morning, Tom and Monkey will begin in the starting cell and will each attempt to make their way to the ending cell, by repeatedly moving from cell to adjacent cell (up, right, down, or left) at a rate of minute per cell. Tom, having arranged the building, will follow a route allowing him to reach the ending cell as quickly as possible. Monkey, on the other hand, will follow the following procedure:
- Make an ordered list of possible next cells to move to as follows: for each of the directions up/right/down/left (in that order), if the cell adjacent to his current one in that direction is within the grid and doesn't contain a wall, include it in the list. Note that this list will always contain between and cells, inclusive.
- Move to the cell in the list which is closest to the ending cell by Manhattan distance* (ignoring any walls). If multiple cells in the list have the same minimum Manhattan distance to the ending cell, choose the one which appears earliest in the list.
- If he's arrived at the ending cell, stop. Otherwise, return to step .
Note: The Manhattan distance between a cell in (row , column ) and another cell in (row , column ) is defined as .
For example, consider the following two building layouts (with S
denoting the starting cell, E
denoting the ending cell, and walls
marked with #
):
|
Monkey would reach the ending cell after minutes (following the sequence of moves: down, down, down, left, left, left). |
|
Monkey would walk around forever (following the sequence of moves: down, down, down, up, down, up, down, up, ...). |
Help Tom come up with any building layout which would cause Monkey to successfully arrive at the ending cell from the starting one eventually (rather than walking around forever as in the second example above), but at least minutes after Tom does. It's guaranteed that at least one such building layout exists for any valid pair of dimensions and (with ).
Subtasks
In test cases worth of the points, and .
Input Specification
The first and only line of input consists of two space-separated integers, and .
Output Specification
Output lines of characters each, a grid representing the chosen building layout. Each character must be one of the following:
S
: starting cell (which must appear exactly once)E
: ending cell (which must appear exactly once).
: vacant cell#
: wall
Sample Input 1
4 2
Sample Output 1
ES
..
.#
#.
Sample Explanation 1
For this grid, both Tom and Monkey would reach the ending cell in minute, by moving to the left. This is a difference of , which is at least as large as the minimum required difference of . Therefore, this output would be judged as correct.
Sample Input 2
10 9
Sample Output 2
.........
.........
.........
.........
.........
.........
.........
....#....
.S#...#E.
.........
Sample Explanation 2
For this grid, Monkey would reach the ending cell in 10 minutes (following the sequence of moves: up, right, right, down, right, right, up, right, right, down), while Tom would only require minutes (following the sequence of moves: down, right, right, right, right, right, right, up). This is a difference of , which is smaller than the minimum required difference of . Therefore, this output would be judged as incorrect. Various other grids exist which would be judged as correct, however they are not disclosed here.
Comments