CF370D.Broken Monitor
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Innocentius has a problem — his computer monitor has broken. Now some of the pixels are "dead", that is, they are always black. As consequence, Innocentius can't play the usual computer games. He is recently playing the following game with his younger brother Polycarpus.
Innocentius is touch-typing a program that paints a white square one-pixel wide frame on the black screen. As the monitor is broken, some pixels that should be white remain black. Polycarpus should look at what the program displayed on the screen and guess the position and size of the frame Innocentius has painted. Polycarpus doesn't like the game but Innocentius persuaded brother to play as "the game is good for the imagination and attention".
Help Polycarpus, automatize his part in the gaming process. Write the code that finds such possible square frame that:
- the frame's width is 1 pixel,
- the frame doesn't go beyond the borders of the screen,
- all white pixels of the monitor are located on the frame,
- of all frames that satisfy the previous three conditions, the required frame must have the smallest size.
Formally, a square frame is represented by such pixels of the solid square, that are on the square's border, that is, are not fully surrounded by the other pixels of the square. For example, if the frame's size is d = 3, then it consists of 8 pixels, if its size is d = 2, then it contains 4 pixels and if d = 1, then the frame is reduced to a single pixel.
因诺琴提乌斯遇到了一个问题——他的电脑显示器坏了。现在有些像素点“死亡”了,也就是说,它们始终显示为黑色。因此,因诺琴提乌斯无法正常玩通常的电脑游戏。他最近正和弟弟波利卡普斯一起玩下面这个游戏。
因诺琴提乌斯正在盲打一段程序,该程序在黑色屏幕上绘制一个边框宽度为 1 像素的白色正方形边框。但由于显示器损坏,本应显示为白色的某些像素点仍保持黑色。波利卡普斯需要观察程序在屏幕上实际显示的内容,并据此推测出因诺琴提乌斯所绘制边框的位置与尺寸。波利卡普斯并不喜欢这个游戏,但因诺琴提乌斯说服了弟弟,称“这游戏有助于锻炼想象力和注意力”。
请帮助波利卡普斯,将他在游戏中的任务自动化。编写一段代码,找出满足以下条件的可能的正方形边框:
- 边框宽度为 1 像素;
- 边框不超出屏幕边界;
- 显示器上所有白色像素均位于该边框上;
- 在所有满足前述三个条件的边框中,所求边框的尺寸必须最小。
形式化地,一个正方形边框由某个实心正方形的所有边界像素构成,即那些未被该正方形其余像素完全包围的像素。例如,若边框尺寸为 d=3,则它由 8 个像素组成;若尺寸为 d=2,则包含 4 个像素;而若 d=1,则边框退化为单个像素。
输入格式
The first line contains the resolution of the monitor as a pair of integers n, m (1 ≤ n, m ≤ 2000). The next n lines contain exactly m characters each — the state of the monitor pixels at the moment of the game. Character "." (period, ASCII code 46) corresponds to the black pixel, and character "w" (lowercase English letter w) corresponds to the white pixel. It is guaranteed that at least one pixel of the monitor is white.
第一行包含显示器的分辨率,为一对整数 n、m(1 ≤ n, m ≤ 2000)。接下来的 n 行每行恰好包含 m 个字符,表示游戏当前时刻显示器像素的状态。字符 .(英文句点,ASCII 码为 46)对应黑色像素,字符 w(小写英文字母 w)对应白色像素。保证显示器中至少有一个像素为白色。
输出格式
Print the monitor screen. Represent the sought frame by characters "+" (the "plus" character). The pixels that has become white during the game mustn't be changed. Print them as "w". If there are multiple possible ways to position the frame of the minimum size, print any of them.
If the required frame doesn't exist, then print a single line containing number -1.
打印显示器屏幕。用字符 “+”(加号字符)表示所求的边框。游戏中变为白色的像素不得更改,应以 “w” 表示。若存在多种方式放置最小尺寸的边框,则输出其中任意一种即可。
如果不存在满足要求的边框,则输出单独一行数字 -1。
输入输出样例
输入#1
4 8 ..w..w.. ........ ........ ..w..w..
输出#1
..w++w.. ..+..+.. ..+..+.. ..w++w..
输入#2
5 6 ...... .w.... ...... ..w... ......
输出#2
...... +w+... +.+... ++w... ......
输入#3
2 4 .... .w..
输出#3
.... .w..
输入#4
2 6 w..w.w ...w..
输出#4
-1
说明/提示
In the first sample the required size of the optimal frame equals 4. In the second sample the size of the optimal frame equals 3. In the third sample, the size of the optimal frame is 1. In the fourth sample, the required frame doesn't exist.
在第一个样例中,最优边框的所需尺寸为 4。在第二个样例中,最优边框的尺寸为 3。在第三个样例中,最优边框的尺寸为 1。在第四个样例中,所需的边框不存在。
输入解题思路,AI测评打分。不知道怎么写?