306636: CF1227E. Arson In Berland Forest

Memory Limit:512 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Arson In Berland Forest

题意翻译

在一个无限大的矩阵中,每个位置是一棵树。在一个 $n \times m$ 的子矩阵中,发生了一场火灾,一些树被摧毁了。被摧毁的树用字符 `X` 表示,未被摧毁的树用字符 `.` 表示。子矩阵外的树都没有被摧毁。 - 在 $0$ 时刻,有些树是自发着火的。 - 接下来的每一分钟内,每一棵着火(也即,被摧毁)的树,会使得它周围的 $8$ 个相邻的树着火。 - 在第 $T$ 分钟初,火灾停止。 现在给定最后被摧毁的树,求最大可能的 $T$,并求出任意一种满足的、自发着火的树的集合。

题目描述

The Berland Forest can be represented as an infinite cell plane. Every cell contains a tree. That is, contained before the recent events. A destructive fire raged through the Forest, and several trees were damaged by it. Precisely speaking, you have a $ n \times m $ rectangle map which represents the damaged part of the Forest. The damaged trees were marked as "X" while the remaining ones were marked as ".". You are sure that all burnt trees are shown on the map. All the trees outside the map are undamaged. The firemen quickly extinguished the fire, and now they are investigating the cause of it. The main version is that there was an arson: at some moment of time (let's consider it as $ 0 $ ) some trees were set on fire. At the beginning of minute $ 0 $ , only the trees that were set on fire initially were burning. At the end of each minute, the fire spread from every burning tree to each of $ 8 $ neighboring trees. At the beginning of minute $ T $ , the fire was extinguished. The firemen want to find the arsonists as quickly as possible. The problem is, they know neither the value of $ T $ (how long the fire has been raging) nor the coordinates of the trees that were initially set on fire. They want you to find the maximum value of $ T $ (to know how far could the arsonists escape) and a possible set of trees that could be initially set on fire. Note that you'd like to maximize value $ T $ but the set of trees can be arbitrary.

输入输出格式

输入格式


The first line contains two integer $ n $ and $ m $ ( $ 1 \le n, m \le 10^6 $ , $ 1 \le n \cdot m \le 10^6 $ ) — the sizes of the map. Next $ n $ lines contain the map. The $ i $ -th line corresponds to the $ i $ -th row of the map and contains $ m $ -character string. The $ j $ -th character of the $ i $ -th string is "X" if the corresponding tree is burnt and "." otherwise. It's guaranteed that the map contains at least one "X".

输出格式


In the first line print the single integer $ T $ — the maximum time the Forest was on fire. In the next $ n $ lines print the certificate: the map ( $ n \times m $ rectangle) where the trees that were set on fire are marked as "X" and all other trees are marked as ".".

输入输出样例

输入样例 #1

3 6
XXXXXX
XXXXXX
XXXXXX

输出样例 #1

1
......
.X.XX.
......

输入样例 #2

10 10
.XXXXXX...
.XXXXXX...
.XXXXXX...
.XXXXXX...
.XXXXXXXX.
...XXXXXX.
...XXXXXX.
...XXXXXX.
...XXXXXX.
..........

输出样例 #2

2
..........
..........
...XX.....
..........
..........
..........
.....XX...
..........
..........
..........

输入样例 #3

4 5
X....
..XXX
..XXX
..XXX

输出样例 #3

0
X....
..XXX
..XXX
..XXX

Input

题意翻译

在一个无限大的矩阵中,每个位置是一棵树。在一个 $n \times m$ 的子矩阵中,发生了一场火灾,一些树被摧毁了。被摧毁的树用字符 `X` 表示,未被摧毁的树用字符 `.` 表示。子矩阵外的树都没有被摧毁。 - 在 $0$ 时刻,有些树是自发着火的。 - 接下来的每一分钟内,每一棵着火(也即,被摧毁)的树,会使得它周围的 $8$ 个相邻的树着火。 - 在第 $T$ 分钟初,火灾停止。 现在给定最后被摧毁的树,求最大可能的 $T$,并求出任意一种满足的、自发着火的树的集合。

加入题单

算法标签: