这几天在练习CF的时候,有一题TLE了,这里是原题(CF 1600J):
J. Robot Factory
time limit per test: 1 second
memory limit per test: 256 megabytes
inputstandard input
outputstandard output
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.
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 its 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.
It is guaranteed that the construction always has walls on its edges. The input will be correct.
Your task is to print the size of the rooms from biggest to smallest.
Input
The first line has two numbers which are N and M, the size of the construction. Both are integers:
n ( 1 ≤ n ≤ 1 0 3 ) n(1≤n≤10^3)