Counting Rooms


Submit solution


Points: 8 (partial)
Time limit: 2.0s
Python 5.0s
Memory limit: 256M

Problem type

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 Specification

The first 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).

Output Specification

Print one integer: the number of rooms.

Constraints

\(1 \le n,m \le 1000\)

Sample Input

5 8
########
#..#...#
####.#.#
#..#...#
########

Sample Output

3

Comments


  • 0
    Deo  commented on Sept. 25, 2025, 1:57 p.m.

    is there necessarily a border of '#'s around each building or can there be a '.' on the edge of the building like

    '###'

    '## .'

    '###'

    is this a valid building


    • 0
      Deo  commented on Sept. 25, 2025, 2:06 p.m.

      nvm im cracked