Hide

# Square Rooms

Bob Roberts is an archaeologist who specializes in the buildings of an ancient race known as the Erauqs. This ancient race was known not only for the fabulous treasures they amassed over the years, but also for the peculiar room layouts of their buildings. Their buildings were always rectangular and the rooms inside the buildings were always square shaped. (To preserve this property, some areas of the building were filled with solid rock.)

When Bob comes across evidence of a buried Erauqi building, he first uses an ultrasound device to find out as much about the layout of the building as possible before he starts digging. The ultrasound can tell him the location of any treasure and the rock locations, but it is not accurate enough to determine the locations of the walls. However, Bob knows that wall locations can be determined from the fact that the Erauqs always put exactly one treasure in each square room. For example, if the ultrasound were to show the locations of treasures and rock as shown in the left of Figure 1, then the only possible layout of the rooms would be as shown on the right.

Occasionally, Bob comes across a building by a rival tribe, the Elgnatcer. In these cases, it is not possible to find room layouts that are compatible with Erauqi architectural principles.

Bob’s come to you to write a program to locate the walls of the square Erauqi treasure rooms and to identify the non-Erauqi buildings. Frankly, the problem has been driving him up a wall.

Input starts with a line containing two integers $n$ $m$ ($1\leq n,m\leq 100$), the number of rows and columns in the building grid. Following this are $n$ lines each containing $m$ characters. These characters are either ‘$’, ‘#’ or ‘.’ for treasure, rock or empty space. There are at least$1$and no more than$52$treasures. ## Output For each test case, if there is no way to assign square rooms to all of the empty spaces in such a way that each room contains one treasure, output elgnatcer. Otherwise, output an$n$by$m$grid indicating the layout of the Erauqi building. Assign to each square room a letter, starting with ‘A’, then ‘B’, ‘C’, …, ’Z’, ’a’, …, ’z’. Room labels are assigned by moving left to right across each row, starting at the topmost row (the first input row for the test case), and assigning the next room label to each unlabeled room as it is encountered. Each grid square in the output should contain either the corresponding room label or the character ‘#’ indicating rock. Sample Input 1 Sample Output 1 7 8 ........ .$....$.$...$... ......#$
.$....#$
...$....$$.....$

AABBBCCC
AABBBCCC
DDBBBCCC
DDEEEE#F
GGEEEE#H
GGEEEEII
JKEEEEII


Sample Input 2 Sample Output 2
1 5
#$#$#

#A#B#


Sample Input 3 Sample Output 3
1 5
#$.$.

elgnatcer

CPU Time limit 2 seconds
Memory limit 1024 MB
Difficulty 6.4hard
Statistics Show
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 1, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.6785317063331604, "perplexity": 1199.098833435064}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2022-33/segments/1659882571987.60/warc/CC-MAIN-20220813202507-20220813232507-00488.warc.gz"}