CF1227E.Arson In Berland Forest

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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×mn \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 00 ) some trees were set on fire. At the beginning of minute 00 , 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 88 neighboring trees. At the beginning of minute TT , the fire was extinguished.

The firemen want to find the arsonists as quickly as possible. The problem is, they know neither the value of TT (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 TT (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 TT but the set of trees can be arbitrary.

输入格式

The first line contains two integer nn and mm ( 1n,m1061 \le n, m \le 10^6 , 1nm1061 \le n \cdot m \le 10^6 ) — the sizes of the map.

Next nn lines contain the map. The ii -th line corresponds to the ii -th row of the map and contains mm -character string. The jj -th character of the ii -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 TT — the maximum time the Forest was on fire. In the next nn lines print the certificate: the map ( n×mn \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
    
首页