Editorial for OTHS Coding Competition 2 P5 - Coffee Jelly
Submitting an official solution before solving the problem yourself is a bannable offence.
Authors:
,To solve this problem, we can employ a search algorithm. For each unvisited open space, we initiate a flood fill via a depth first search in which we explore all 4 possible directions (up, down, left, right) to find all connected open spaces. During the flood fill, we will keep track of whether we encounter a person. If we do, we mark the current classroom as "not empty". After completing the flood fill for each unvisited open space, if the classroom was found to be empty (i.e., it did not touch any *
), we increment our count of empty classrooms. Ensure to reset the variable used to track the state of the room after every DFS.
Time Complexity:
Alternate solution
Start DFS at every unvisited cell containing *
and turn the entire open space containing it into walls. Then count the number of unvisited open spaces using DFS.
Time Complexity:
Comments