#P11222. [COTS 2019] 车位安排 Parking
[COTS 2019] 车位安排 Parking
Background
Translated from Izborne Pripreme 2019 (Croatian IOI/CEOI Team Selection) D1T2。。
Problem Description
The city government of Zagreb decided to build a new parking lot.
The land is an rectangle, divided into rows and columns, i.e. cells. We denote the cell in row and column by .
To attract tourists, some cells are pre-determined to contain water scenery. The remaining cells will be converted into parking spaces or lanes. In particular, the entrance/exit of the parking lot is , and it can only be used as a lane.
Cars can move freely inside the parking lot. Each move can go to one of the four adjacent cells (up, down, left, right), as long as the destination cell is still inside the parking lot.
A valid construction plan must satisfy the following condition:
- For any car parked in a parking space, it must be able to reach the entrance/exit of the parking lot without passing through any other parking space.
Among all valid construction plans, find the maximum possible number of parking spaces.
Input Format
The first line contains two positive integers .
Next, an character matrix describes the land.
- The character in row and column is
., meaning it can be used as either a lane or a parking space. - The character in row and column is
X, meaning it is used to build water scenery.
Output Format
Output one integer in one line, the maximum number of parking spaces that can be built.
3 3
...
.x.
...
2
3 3
...
..x
...
4
3 6
.x..x.
..x.x.
......
3
4 5
....x
....x
..x..
.x..x
7
Hint
Explanation for sample : let P denote a parking space, as follows.
.PPPx
....x
.Px.P
PxP.x
For of the data, it is guaranteed that:
- ;
- ;
- No water scenery will be built at 。
Constraints:
| Subtask ID | Score | ||
|---|---|---|---|
Translated by ChatGPT 5