mlp-laser
Mirko has received a superlaser as a birthday gift from his auntie who lives in America. Having obsession with it, Mirko has rented a room with plenty of mirrors.
The room is square-shaped grid consisting of NxN squares, and is surrounded by 4 walls with some holes in them. A square is either empty or there is a mirror on it, which can be oriented in two ways: direction 0 ('\') or direction ('/'). The mirrors are arranged in such a way that in there are no more than two mirrors in any row or mirror. There is a total of M mirrors in the room.
For security reasons, Mirko will first place a laser into one of the holes on the wall (note that there are exactly 4*N holes), and then, using remote conrol, he will switch his superlaser on, emitting a beam in a directed opposite to the wall the laser had been put into. The beam goes straight in one direction, until it hits a mirror when it reflectes sideways (90 degrees left or right, depending on the mirror type), continuing its path throughout the room until it hits a wall.
Below is shown a path of the beam shot from the mid of the left wall../xx\
.x..x
x/xx/
.x...
.x\/.
To properly test the laser, Mirko wants to maximize the number of reflections. To achieve this, Mirko is allowed to change the orientation of at most K mirrors (from direction 0 to 1 or vice-versa), otherwise the boss would have noticed and Mirko would be in huge problems.
Write a program which that, assuming the optimal placement of the laser and optimal reorientation of no more than K mirrors, computes and outputs the maximum number of beam reflections.
The first line contains three non-negative integers, N (N <= 100000), M (M <= 2*N) and K (K <= 2*N) respectively.
The following M lines contain three integers Ri, Ci and Di, which represent the 0-based coordinates and orientation of the i-th mirror.
Output the maximum number of reflections.
Input:
5 6 1
0 0 1
0 2 1
2 2 1
2 4 1
4 0 0
4 4 1
Output:
6
The initial state of the room looks like this:
/./..
.....
.././
.....
\.../If we orient the mirror at (2,4) to direction 0 and shoot the beam from the mid of the bottom wall (column no. 2, upwards), we have 6 reflections.
Input:
1 1 0
0 0 1
Output:
1
Input:
5 6 2
0 0 1
0 2 1
2 2 1
2 4 1
4 0 0
4 4 1
Output
7
Submit solution
Coming laterThe grading service will be connected in a later migration step. You can inspect the task and your previous results now.