Woburn Challenge 2015-16 Round 2 - Junior Division
After the destruction of the Death Star and death of Darth Sidious, victory for the rebel forces seemed apparent. However, that proved to be far from the truth, as the true puppeteer behind the Galactic Empire finally revealed himself – Sith lord Jar Jar Binks. His vengeance was swift, as he all but eradicated the rebels' resistance and the Jedi presence.
Fortunately, Han Solo was able to survive Jar Jar's wrath, and has a plan to destroy him and topple the Empire. Jar Jar has been tricked into entering an abandoned mirror factory, where he will hopefully bring about his own doom.
Viewed from above, the factory can be divided into a regular grid of cells, with rows and columns . The nature of the -th cell in the -th row is given by the character , with the following possibilities:
.
- The cell is empty.#
- The cell contains a non-reflective barrier./
- The cell contains a diagonal mirror running from the top-right to the bottom-left, which reflects any incoming laser at a -degree angle (for example, a laser entering from the top would leave through the left).\
- The cell contains a diagonal mirror running from the top-left to the bottom-right, which reflects any incoming laser at a -degree angle (for example, a laser entering from the left would leave through the bottom).X
- The cell contains a set of mirrors which reflect any incoming laser back the way it came (for example, a laser entering from the top would leave back through the top).
As Jar Jar walks through the factory, Han will goad him into firing a blaster shot in some cardinal direction (directly up, down, left, or right) from some empty cell. He hopes that the laser will happen to reflect off some mirrors and end up re-entering that same cell, thus killing Jar Jar! That might sound like an unlikely plan to work… but never tell him the odds.
That being said, enquiring minds might like to know what kind of a chance it does have. An empty cell is considered to be "deadly" if, for at least one of the four cardinal directions, Jar Jar would shoot himself if he were to fire a shot from that cell in that direction. How many of the empty cells are deadly?
Note: In test cases worth 80% of the points, and .
Input Specification
The first line of input consists of two space-separated integers and
.
The next lines each consist of characters ,
for .
Output Specification
Output a single integer – the number of empty cells that are considered deadly.
Sample Input
5 6
/.\...
./.\.X
\.....
/\./X#
\/.#\.
Sample Output
12
Explanation
The following images depict the scenario in the sample input. Cells labeled with blue circles are considered deadly.
Comments