#P3836. [IOI 2017] Nowruz

    ID: 2793 远端评测题 5000ms 512MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>搜索贪心2017IOI提交答案Special Judge深度优先搜索,DFS

[IOI 2017] Nowruz

Description

Nowruz (the Persian New Year) is in a few days. Grandfather has invited his whole family to gather in his garden. Among the many guests, there are kk children. To make the party more fun for them, Grandfather plans to let them play hide-and-seek.

The entire garden can be seen as an m×nm \times n grid of cells. Some cells (possibly none) are blocked by rocks; the remaining cells are called empty cells. If two cells share a side, they are called neighbors. Therefore, each cell has at most 44 neighbors: two horizontal and two vertical. Grandfather wants to turn the garden into a maze. To do this, he will plant bushes on some empty cells to block them; those cells then cease to be empty.

A maze must satisfy the following property: for any pair of empty cells aa and bb, there is exactly one simple path between them. A simple path from aa to bb is a sequence of distinct cells starting at empty cell aa and ending at empty cell bb, where every two consecutive cells are neighbors.

A child can hide in a cell if and only if the cell is empty and it has exactly one empty neighbor. At most one child can hide in a single empty cell.

You are given a map of the entire garden. Your task is to help Grandfather construct a maze that allows as many children as possible to hide.

Scoring

A valid output file must satisfy all of the following:

  • Apart from changing any number of . characters in the input to X (i.e., planting bushes), the output map must be identical to the input map.
  • The output map must satisfy all the maze properties stated above.

For a given testdata, if your output is not valid, your score for this testdata is 00. Otherwise, your score is min(10,10l/k)\min(10, 10 \cdot l / k), rounded down to two decimal places, where ll is the maximum number of children that can hide in your output maze, and kk is the number of children specified in the input file. You receive 1010 points for a testdata if and only if your output maze can hide at least kk children.

For every testdata there exists a solution worth 1010 points.

Note: If your output is valid but the above formula still yields a score of 00, the judging system will display “Wrong Answer”.

Input Format

This is an output-only problem with partial scoring. There are 1010 input files describing Grandfather’s garden. For each input file, you should submit an output file containing a maze map. Your score is based on the number of children that can hide in the maze you submit for each input file.

You do not need to submit any source code.

Each input file describes the garden grid and gives the number of invited children kk, in the following format:

Line 11: m n km \ n \ k.

Line 1+i1 + i (1im1 \leqslant i \leqslant m): the ii-th row of the grid, a string of length nn with no spaces, consisting of:

  • .: an empty cell,
  • #: a rock.

Output Format

Line ii (1im1 \leqslant i \leqslant m): the ii-th row of the maze (the garden after planting bushes). It is a string of length nn with no spaces, consisting of:

  • .: an empty cell,
  • #: a rock,
  • X: a bush (note that the letter X must be uppercase).
4 5 5
....#
.#..#
...#.
....#
.X.X#
.#..#
...#X
XX..#

//这是其中一个有效的输出

Hint

The sample output is one valid output.

For this output, since l=4l = 4 children can hide in the maze, the score is 104/5=810 \cdot 4 / 5 = 8. The cells where children can hide are marked with O below:

OXOX#
.#.O#
...#X
XX.O#

The following three outputs are invalid:

.XXX#    ...X#    XXXX#
.#XX#    .#.X#    X#XX#
...#.    ...#X    ..X#X
XX..#    XXXX#    ..XX#

In the leftmost output, there is no simple path between the empty cell in the top-left corner and the empty cell in the rightmost column near the bottom-right.

In each of the other two outputs, there are two simple paths between some pair of empty cells.

Constraints

1m,n10241 \leqslant m, n \leqslant 1024.

Translated by ChatGPT 5