Editorial for COCI '08 Regional #3 Cijevi


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

First write four auxiliary functions left(r,c), right(r,c), up(r,c) and down(r,c) telling us if gas can flow in each direction from empty cell (r,c). For example, the function left(r,c) can look like this:

return true if Map(r,s-1) = '+' or Map(r,s-1) = '-' or Map(r,s-1) = '1' or Map(r,s-1) = '2'

The task can be solved in one pass through the map. For every empty cell (r,c), we run the following checks:

if left(r,c) and right(r,c) and up(r,c) and down(r,c) then output r c '+'
else if left(r,c) and right(r,c) then output r c '-'
else if up(r,c) and down(r,c) then output r c '|'
else if right(r,c) and down(r,c) then output r c '1'
else if right(r,c) and up(r,c) then output r c '2'
else if left(r,c) and up(r,c) then output r c '3'
else if left(r,c) and down(r,c) then output r c '4'

Comments

There are no comments at the moment.