DWITE '07 R2 #3 - Floor Plan

View as PDF

Submit solution

Points: 7
Time limit: 1.0s
Memory limit: 64M

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig
DWITE Online Computer Programming Contest, November 2007, Problem 3

A common way to value a house, among other things, is by the area of the rooms. Though it could be less than trivial to accurately calculate the area of a room that is not in a standard shape. Given a floor plan diagram, with rooms of interest marked, their areas should be calculated.

The input will contain two lines with one integer value each, R, C; 0 \le R, C \le 40, representing the number of Rows and Columns that make up the floor plan. Followed by R lines, showing the floor plan layout, where:

  • # - wall
  • . - open space
  • {1..5} - integers 1 to 5, marking rooms of interest

The output will contain 5 lines. Each line will have an integer representing the area of a room of interest. First line should contain the area of room 1, second line of room 2, etc.

The area of the room is defined as 1\ + number of adjacent open spaces. The integer marker could appear anywhere inside the room.

Sample Input

5
6
1###..
##4#5.
2#####
.#.#..
...#.3

Sample Output

1
6
4
1
4

Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0) Problem Resource: DWITE


Comments


  • -3
    aayushICS  commented on Feb. 21, 2019, 9:14 p.m.

    Why does Room 2 have an area of 6?


    • -1
      Narcariel  commented on March 2, 2020, 5:07 p.m.

      The number counts as a space in the room.