Jonathan Sumabat 8

View as PDF

Submit solution

Points: 7
Time limit: 2.0s
Memory limit: 64M

Author:
Problem type

Jonathan Sumabat watches a lot of anime. He is such a big fan of anime that he decides to attend an anime convention. After hours of driving, he finally arrives at a strange looking place. Due to his poor navigational skills Jonathan Sumabat is not sure that this is where the convention takes place. On his ticket, it says that the convention center is located at the bottom of a square spiral staircase so Jonathan Sumabat decides to compare the staircase of the place he drove to in order to determine whether or not he is at the correct location.
A square spiral staircase turns inwards in a rectangular shape starting from the top left and only turning at 90 degrees to the right. The stairs consist of the * character. The length of each side of the staircase does not matter but the staircase must be exactly 1 unit wide. The staircase may end at any point. Any given stair on a square spiral staircase is only accessible by exactly 2 other stairs, except for the beginning and end which are accessible by 1 other stair. Some examples of valid square spiral staircases:

*******.
......*.
***...*.
*.....*.
*******.
........
***********
..........*
..........*
....*****.*
....*...*.*
....*.***.*
....*.....*
....*******

The following are not valid square spiral staircases:

.........
*********
........*
*******.*
*.......*
*********

Note that the staircase does not begin at the top left corner.

******..
.....***
****...*
*......*
********

Note that the staircase does not only turn to the right at 90 degrees.

Input Specification

The first line of input R (5 \le R \le 100) is the number of rows in the grid that represents the staircase.
The next line of input C (5 \le C \le 100) is the number of columns in the grid that represents the staircase.
The next R lines contain C characters, either a * or a .. The staircase is represented by an area of * characters. It is guaranteed there will only be a single such area that is connected either directly up, left, down or right by * characters.

Output Specification

If the grid represents a valid square spiral staircase, output anime!. Otherwise, output lost!.

Sample Input

6
8
*******.
......*.
***...*.
*.....*.
*******.
........

Sample Output

anime!

Comments

There are no comments at the moment.