PDP-22 (2010) - Phase B' Senior High School (fire)

View as PDF

Submit solution

Points: 20 (partial)
Time limit: 1.0s
Memory limit: 64M

Author:
Problem types
Allowed languages
C, C++, Java, Pascal, Python

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 N \times M is given, where N and M are integers (1 \le N,\; M \le 1000).
The region is divided into rectangular areas of area 1 \times 1, 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 X and Y, where X and Y are integers (1 \le X \le N,\; 1 \le Y \le M). X is the horizontal coordinate, and Y is the vertical. Segment (1,\;1) 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 C of forested segments that will burn (assuming no extinguishing), where C is an integer with (1 \le C \le M * M).
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 N and M representing the dimensions of the region, separated by a space.
The second line contains two numbers N_f and M_f, which specify the coordinates of the forested segment where the fire starts, separated by a space.
The next M lines each contain exactly N 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 C, 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
  1. We assume that the input files contain only the allowed characters, and therefore, no correctness check is required.
  2. Maximum Execution Time 1 sec.

Comments

There are no comments at the moment.