Connection Status:
Competition Arena > GalleryIllumination
SRM 805 · 2021-05-06 · by misof · Brute Force, Simple Search, Iteration, Simulation
Class Name: GalleryIllumination
Return Type: int
Method Name: countDarkCells
Arg Types: (int, int, vector<string>)
Problem Statement

Problem Statement

The inside of an old warehouse has recently been repurposed as a gallery. The floor of the warehouse is a rectangle that is divided into R rows by C columns of unit squares. Some unit squares are walls ('#'), others contain lamps ('O'), and the rest is empty ('.'). You are given R, C, and the floor plan itself in the String[] floorPlan.

Each lamp illuminates not just its own square but also other empty squares in its row and column - but only until the first wall in each direction.

Compute and return the number of empty squares that will remain in the dark, even if all lamps are turned on.

Notes

  • The character used to represent a lamp is 'O', the capital letter oh (and not '0', the digit zero).

Constraints

  • R will be between 1 and 50, inclusive.
  • C will be between 1 and 50, inclusive.
  • floorPlan will contain R elements.
  • Each element of floorPlan will contain C characters.
  • Each character in floorPlan will be '#', 'O', or '.'.
Examples
0)
3
4
{"....",
 "....",
 "...."}
Returns: 12

There are no lights, the whole warehouse is in the dark.

1)
4
5
{".....",
 ".O...",
 ".....",
 "....."}
Returns: 12

A single light. When we turn it on, the warehouse looks like we show below, with '*' denoting cells that have light. .*... *O*** .*... .*...

2)
4
5
{".....",
 ".OO..",
 ".....",
 "....."}
Returns: 9

.**.. *OO** .**.. .**..

3)
4
5
{".....",
 ".O#..",
 ".#.O.",
 "....."}
Returns: 9

In this example we also have two walls that block the light partially. .*.*. *O#*. .#*O* ...*.

4)
4
5
{".....",
 ".O...",
 "...O.",
 "....."}
Returns: 6

Submissions are judged against all 64 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class GalleryIllumination with a public method int countDarkCells(int R, int C, vector<string> floorPlan) · 64 test cases · 2 s / 256 MB per case

Submitting as anonymous