P25308 [AtCoder] Automatic Map Generator
普及
题目描述

Problem Description

Input Format

Inputs will be given by standard input in the following format:

$ H $ $ W $ $ K $

  • At the first line, $H\ (1\ ≦\ H\ ≦\ 100)$, $W\ (1\ ≦\ W\ ≦\ 100)$, and $K\ (1\ ≦\ K\ ≦\ 10,000)$ will be given divided by spaces.

Output Format

Output IMPOSSIBLE if it is impossible to draw exactly $ K $ islands. Otherwise, output $ H $ lines where the $ i_{th} $ line has $ W $ letters, and the $ j_{th} $ letter from the left side of the $ i_{th} $ line must be the letter that Cat Snuke draws on her paper.

If there are multiple possible solutions, it is allowed to output any of them.

Print a newline at the end of the output.

Sample Input and Output

Sample Input #1

6 7 4

Sample Output #1

#.#####
..#...#
#.#.#.#
#.#...#
#..####
.#..###

Sample Input #2

2 4 3

Sample Output #2

IMPOSSIBLE

Sample Input #3

20 50 10

Sample Output #3

..................................................
...........................................#......
..........................................#.......
..................................................
..........................................#.......
..............................................#...
.....................................##..#....##..
.........................................##..###..
..........................#...............#####...
..........................................####....
.........................................###......
......##...............#..............#.#.........
.......##.............................##..........
........#.............................###.........
.....................................##...........
.............................#.......##...........
.............................#..#.................
...........................#....#.................
..................................................
..................................................

Notes/Hints

Problem

As is known to all, Okinawa is comprised of various islands. Cat Snuke wants to draw a simple map to include some of these islands. However, since the size of the paper is limited, Snuke will not be able to draw the map in detail.

Therefore, Cat Snuke divides the paper into grids, which have $ H $ horizontal rows and $ W $ vertical columns. For each block of the grids, it will be filled with either a . that represents the sea or a # that represents the land.

Each island consists of blocks of land. For two blocks that represent land, we say that they belong to the same island if they had coincident edges or vertices, or they were connected by other blocks that have coincident edges or vertices. Otherwise, we say these two blocks belong to different islands.

Suppose that there is only sea beyond Snuke’s map. Also, please note that the blocks of land that are surrounded by sea and are surrounded by an island belong to another island (rather than the outer island).

Cat Snuke needs to follow the rules above to draw exactly $ K $ islands on the paper. Please decide whether Snuke is able to draw. If your answer was yes, please find a solution.

Sample Explanation 1

There are four islands. Although the land block at the 3rd row from the top and the 5th column from the left is surrounded by an outer island, they are separated because there is sea between them and they share no edges nor vertices.

Sample Explanation 2

The paper is too small to draw a map that satisfies the conditions.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
6 7 4
样例输出
#.##### ..#...# #.#.#.# #.#...# #..#### .#..###