InterNAV

View as PDF

Points: 7
Time limit: 1.0s
Python 3 2.5s
Memory limit: 128M

Authors:
Problem type

Henry Two had been working on a GPS system for the school itself, and after years of hard work, he realizes that what he had been making already exists. Therefore, he needs to make his better. Given an by grid, where each position is either a numbered room, an empty space, or a wall, determine which rooms Henry can go to. Henry starts at room and can only move up, down, left, or right.

Input Specification

The first line will contain the integer , representing the width of the room .
The second line will contain the integer , representing the height of the room .
The next lines will each contain characters, where # represents a wall, O represents an empty space, and a number will represent a room. There will be no more than rooms.

Output Specification

Output the list of room numbers Henry is able to travel to (including room ), separated by spaces and sorted in ascending order.

Sample Input 1

5
4
O3OO2
OOOO#
1###4
#5OOO

Sample Output 1

1 2 3

Sample Input 2

7
8
OOO#2O#
1OOOO#3
OOOOOO#
OOO7OOO
OOOOOOO
##OOO#O
O4#O#5O
6O#OOOO

Sample Output 2

1 2 5 7