There are multiple test cases in the input.
First, you’ll get a 15*15 matrix which indicates the initial situation of the table, characters are defined below:
We define the fields as:
. : Empty grids
* : Grids that have walls
- : Conduits that only allow the light going left and right
| : Conduits that only allow the light going up and down
\ : Conduits that only allow the light going top-left and bottom-right
/ : Conduits that only allow the light going top-right and bottom-left
Define laser guns as:
W : White laser gun
R : Red laser gun
G : Green laser gun
B : Blue laser gun
Pinwheel is our target, define them as:
r : Red pinwheel
g : Green pinwheel
b : Blue pinwheel
y : Yellow (Red + Green) pinwheel
m : Magenta (Red + Blue) pinwheel
c : Cyan (Green + Blue) pinwheel
w : White (Red + Green + Blue) pinwheel
n : Black (You should let no light pass it) pinwheel
Following k (k is the number of laser guns) lines, each line represents the initial direction a laser gun points at. Each line has two integers and a string S, two integers represents the position (x, y) which laser gun is being described. S is “u” (up), “d” (down), “l” (left), “r” (right), “lu” (upper-left), “ld” (bottom-left), “ru” (upper-right) or “rd” (bottom-right).
Next line, represents the tools we are using, characters are defined below:
M : Reflector, or mirror, which reflect the light for 90 degrees or reflect back
A : Bender, is an angled reflector, it bends lasers from horizontal and vertical to the diagonals, and vice versa.
S : Splitter. If a laser hits a splitter at the correct angle, it bounces off at an angle (act exactly like a mirror) and also goes straight through. If it hits head on, it just goes through. Notice that the splitter is two-sided.
D : Doppler. The Doppler turns red beams into green, green into blue, and blue into red-or if you go through it backwards, the opposite. At the beginning, the forward direction is left to right.
P : Prism. A prism has two equal short face and a long face, act just like the third picture (Notice that white beam is consists by RGB together), and it reversible and symmetrical.
T : Teleporter. The teleporter causes laser beams to jump instantaneously to the next teleporter in the same direction as beam is travelling. If there’s no teleporter in that direction, the beam disappears.
1 : Red Filter, that only allows red light go through, if the light is a mixed light that contains red light (like white laser), only red light left after passing (if it can pass through).
2 : Green Filter.
3 : Blue Filter.
Last line contains the string S as said before.
You can be sure that all inputs are legal.
At beginning, tools are initially placed as below:
From left to right: A 2 3 1 S M D P