## Back to School '16: Screensaver

View as PDF

Points:8
Time limit:1.0s
Memory limit:64M
Author:

Problem type

On the first day of school, the computer science teacher shows a couple of impressive screensavers on the computer. The screensaver called :tim: stands out to you, mainly due to the simple rules that govern :tim:.

:tim: is a beautifully rendered three-dimensional arena with a couple of walls and the observer gets to bounce off these walls. The observer occasionally bounces out of the arena, which causes the animation to start again with a new set of walls.

The arena can be represented as a grid with columns and rows. Empty spaces are denoted with . and walls are denoted with the character -, |, / or \. The walls are similar to mirrors; the observer hits the surface of the wall and changes to the corresponding direction. The only exception to this rule is with - and | walls. The observer bounces off - when going vertically, and passes through when going horizontally. The same exception applies when going vertically through the | wall.

One notable feature of :tim: is that whenever the user bounces on a wall, that wall rotates degrees. For example, when the user bounces off the wall with direction |, the wall now has direction -.

Every tick, the observer moves into an adjacent cell in the grid. The player can travel horizontally or vertically, but never diagonally. The observer begins at the cell containing O (not occupied by a wall) and initially moves horizontally to the right. The animation is reset once the observer leaves the grid.

Of course, you want to implement this screensaver yourself! You have the renderer up and running, but you want the screensaver to last more than ticks. Given the grid, can you determine whether the requirement is satisfied?

#### Input Specification

The first line contains the integers , , and .

On each of the next lines, there are characters. It is guaranteed that the character O appears exactly once.

#### Output Specification

If the observer stays within the grid for more than ticks, output The observer stays within the grid.

Otherwise, output The observer leaves the grid after X tick(s).

#### Sample Input 1

4 4 100
O..\
....
....
.-./


#### Sample Output 1

The observer leaves the grid after 10 tick(s).


#### Sample Input 2

2 1 3
O|


#### Sample Output 2

The observer leaves the grid after 3 tick(s).


#### Sample Input 3

2 1 2
O|


#### Sample Output 3

The observer stays within the grid.


• aurpine
commented on Sept. 17, 2016, 8:22 p.m.
Errors Fixed

The sample test cases were correct, the problem statement has been fixed.

• bobhob314
commented on Sept. 17, 2016, 4:01 p.m.
error

same with sample input 2

• bobhob314
commented on Sept. 17, 2016, 4:01 p.m.
error

sample input 3 2 1 3 O| there are two columsn not ros

commented on Sept. 17, 2016, 4:19 p.m.

yeah it's given as: width, height

• bobhob314
commented on Sept. 17, 2016, 4:29 p.m.

naw the setters goofed.

The arena can be represented as a grid with NN rows and MM columns

• bobhob314
commented on Sept. 17, 2016, 3:48 p.m.
oh god

y