6749.Counting Rooms

Time Limit: 1s Memory Limit: 512MB

You are given a map of a building, and your task is to count the number of its rooms. The size of the map is $n \times m$ squares, and each square is either floor or wall. You can walk left, right, up, and down through the floor squares.

Input Format(From the terminal/stdin)

The first input line has two integers $n$ and $m$ : the height and width of the map.

Then there are $n$ lines of $m$ characters describing the map. Each character is either . (floor) or # (wall).

  • $1 \le n,m \le 1000$

Output Format(To the terminal/stdout)

Print one integer: the number of rooms.

Sample Input

Copy
5 8
########
#..#...#
####.#.#
#..#...#
########
 · \n
        \n
        \n
        \n
        \n
        \n

Sample Output

Copy
3
 \n
Source: CSES, Graph Algorithms, 1192

Submit

请先 登录

© 2025 FAQs