#P3108. Laser Redirection

    ID: 16366 Type: Default 1000ms 256MiB

Laser Redirection

Laser Redirection

Farmer John's cows want to put on a dance party in the barn using a laser‐light show. Unfortunately, the only working laser is located at (0,0) and is aimed due north. The barn is located at (Bx,By). There are N cows on the farm each holding a fixed 45° mirror – each mirror is oriented either as / or as \ – placed at distinct integer coordinates. When a beam of light hits one of these mirrors, it is deflected depending on the mirror type. For example, if a beam traveling north (direction (0,1)) hits a / mirror then it turns east (direction (1,0)), while if it hits a \ mirror then it turns west (direction (-1,0)). (The full reflection rules are given below.)

Bessie has noticed that with the mirrors in their current positions the laser beam will not reach the barn. In a last‑minute effort to save the party she plans to run out into the field holding one extra mirror (which, like the others, is set at a 45° angle). Please count the number of locations (grid points) at which Bessie can stand so that if she adds her mirror (she is allowed to choose its orientation optimally) the laser beam will be re‐directed and eventually hit the barn.

Reflection rules:

  • For a / mirror:
    • north (0,1) → east (1,0)
    • east (1,0) → north (0,1)
    • south (0,-1) → west (-1,0)
    • west (-1,0) → south (0,-1)
  • For a \ mirror:
    • north (0,1) → west (-1,0)
    • west (-1,0) → north (0,1)
    • south (0,-1) → east (1,0)
    • east (1,0) → south (0,-1)

It is guaranteed that with the original configuration the laser beam will never return to (0,0) after leaving that point. Note that Bessie is not allowed to stand in a location where a cow is already holding a mirror, nor at (0,0) (the laser position) or at the barn.

inputFormat

The first line contains three space‐separated integers: N (1 ≤ N ≤ 100,000), Bx, and By.

The next N lines each contain two integers and a character: xi, yi and c, where (xi, yi) is the position of a cow’s mirror and c is either / or \ indicating its orientation. All coordinates lie between –1,000,000,000 and 1,000,000,000. No two cows share the same location.

outputFormat

Output a single integer, the number of grid points where Bessie can stand so that placing her mirror (in an optimal orientation) will cause the laser beam to eventually hit the barn.

sample

1 1 2
0 1 /
1