problem.txt (2098B)
1 J. Robot Factory 2 time limit per test1 second 3 memory limit per test256 megabytes 4 You have received data from a Bubble bot. You know your task is to make factory facilities, but before you even start, you need to know how big the factory is and how many rooms it has. When you look at the data you see that you have the dimensions of the construction, which is in rectangle shape: N x M. 5 6 Then in the next N lines you have M numbers. These numbers represent factory tiles and they can go from 0 to 15. Each of these numbers should be looked in its binary form. Because from each number you know on which side the tile has walls. For example number 10 in it's binary form is 1010, which means that it has a wall from the North side, it doesn't have a wall from the East, it has a wall on the South side and it doesn't have a wall on the West side. So it goes North, East, South, West. 7 8 It is guaranteed that the construction always has walls on it's edges. The input will be correct. 9 10 Your task is to print the size of the rooms from biggest to smallest. 11 12 Input 13 The first line has two numbers which are N and M, the size of the construction. Both are integers: 14 15 n 16 (1≤n≤103 17 ) 18 19 m 20 (1≤m≤103 21 ) 22 23 Next N x M numbers represent each tile of construction. 24 25 Output 26 Once you finish processing the data your output consists of one line sorted from biggest to smallest room sizes. 27 28 --- 29 30 - construction size is MxN 31 - factory tiles are bounded from 0 -> 15 32 - consider them in binary 33 - 1111 34 - 1's mean a wall on that side 35 - ordering: 36 - north, east, south west 37 - print room sizes from smallest to largest 38 - it is guaranteed that the construction always has walls on it's edges. The input will be correct. 39 40 --- 41 42 - idea: 43 - for each position: 44 - dfs 45 - each step returns the size of the connected component that's newly visited from the position (there will likely be cycles) 46 - dfs: 47 - go up,left,right,down if there's not a wall on that side 48 - we don't have to check bounds because walls are on edges.