Fires in Greece
Problem (General Description)
Greece, a warm Mediterranean country with numerous forested areas, often faces the problem of wildfires during the summer.
Utilizing every technological means, many efforts are made to predict wildfires based on complex meteorological, morphological, and forestry data.
In the broader context of environmental protection, significant progress has recently been made in the field of software, offering hope for the effective use of specialized software for predicting and addressing wildfires.
You are tasked with developing a program in one of the IOI languages that simulates a wildfire based on the terrain's morphology.
The goal is to predict the extent of the damage that would occur if the specific wildfire took place, so that areas requiring prevention measures can be identified.
Problem (Detailed Description)
In the model we follow, a rectangular region of size is given, where and are integers .
The region is divided into rectangular areas of area , each of which can be initially recognized as either forested or rocky.
Each segment is determined by the coordinates of the upper-left corner (northwest vertex of and , where and are integers .
is the horizontal coordinate, and is the vertical.
Segment is located in the top-left corner of the map.
The type of each segment is identified by a character.
The dot character specifies a forested segment, while the "@" character specifies a rocky segment.
According to the initial model, when a forested segment ignites, the fire spreads to all adjacent forested segments.
(For the sake of generality, we assume that the wind cannot propagate the fire in only one direction).
Adjacent forested segments are those that border the initially ignited one to the left, right, top, or bottom (but not diagonally).
The fire does not spread to rocky segments. Segments where the fire expands lead to further expansion, as they act as new fire starting segments.
Fire does not spread to a segment that has already burned.
If the coordinates of the forested segment where the fire started are given, your program should calculate the number of forested segments that will burn (assuming no extinguishing), where is an integer with .
Note: A fire cannot start in a rocky or burned segment.
Input File:
The input file named fire.in is a text file with the following structure:
The first line contains the integers and representing the dimensions of the region, separated by a space.
The second line contains two numbers and , which specify the coordinates of the forested segment where the fire starts, separated by a space.
The next lines each contain exactly characters.
These characters are either a dot or an "@" symbol, representing a forested or rocky segment, respectively.
Output File:
The output file named fire.out is a text file with the following structure.
It has a single line with an integer , which indicates the number of segments calculated to be burned if there is no extinguishing.
Examples of Input-Output Files:
1st In the example that follows, the fire starts from the forested segment in the second column and the third row. The fire spreads to the forested areas above, to the right, and below this segment. However, it does not spread to the left because it encounters rocky segments.
STDIN (fire.in)
10 10
2 3
@@@@@@@@@@
@.@@@.@..@
@..@@....@
@...@@..@@
@...@....@
@...@@@@@@
@@@@@@...@
@....@@@@@
@...@@....
@@@@@@@@@@
STDOUT (fire.out)
12
2nd In the following example, the fire starts from the forested segment in the fifth column and the fifth row and becomes trapped there because the segment is surrounded only by rocky segments.
STDIN (fire.in)
10 10
5 5
..........
..........
..........
....@.....
...@.@....
....@.....
..........
..........
..........
..........
STDOUT (fire.out)
1
Notes
- We assume that the input files contain only the allowed characters, and therefore, no correctness check is required.
- Maximum Execution Time 1 sec.
Comments