Under construction

Still being built. Things may change

Landscape Painting

Time limit1sMemory limit1024 MB

Summary
Given an N by M grid of black and white cells, count the mountains and lakes of each size from 1 to N.
Level

Medium6 of 10

Topics
Dynamic programming, Matrix
Solved
No attempts yet

Problem

Yun's hobby is drawing. One day, inspired by the hill behind the school, Yun painted a landscape. The landscape is a grid of NN rows and MM columns, and each cell is painted black or white.

Yun decided to give the painting to Phoenix and Dalgu. However, there was only one painting, so Phoenix and Dalgu began arguing over who should get it. The debate did not end easily because the two had different standards for a good landscape.

Dalgu thinks a landscape with many mountains is good, and Phoenix thinks a landscape with many lakes is good. The definitions of a mountain and a lake are as follows. (i,j)(i,j) denotes the cell in row ii and column jj.

  • If every (a,b)(a,b) satisfying a≤x,∣a−x∣+∣b−y∣≤d−1a\le x,|a-x|+|b-y|\le d-1 is black, this is called a mountain of size dd centered at (x,y)(x,y). Here dd must be an integer with 1≤d≤min⁡(y,M−y+1,x)1 \le d \le \min(y,M-y+1,x).
  • If every (a,b)(a,b) satisfying x≤a≤x+d−1,y≤b≤y+d−1x\le a\le x+d-1,y\le b\le y+d-1 is white, this is called a lake of size dd with its top-left corner at (x,y)(x,y). Here dd must be an integer with 1≤d≤min⁡(N−x+1,M−y+1)1 \le d \le \min(N-x+1,M-y+1).

In the figure above, there is a mountain of size 22 centered at (3,2)(3,2) and a lake of size 22 with its top-left corner at (1,3)(1,3).

To stop the debate, Yun wants to count, for every ii from 11 to NN, the number of mountains of size ii and the number of lakes of size ii. Help Yun solve this problem.

Input

The first line contains the number of rows NN and the number of columns MM, separated by a space. (1≤N,M≤2000)(1 \le N, M \le 2000)

From the second line onward, the next NN lines describe the landscape. Line i+1i+1 is a string of length MM representing row ii of the landscape. Every string consists of # or .. # means black, and . means white.

Output

On the first line, print NN integers A1,A2,⋯ ,ANA_1, A_2, \cdots, A_N, separated by spaces, where AiA_i is the number of mountains of size ii.

On the second line, print NN integers B1,B2,⋯ ,BNB_1, B_2, \cdots, B_N, separated by spaces, where BiB_i is the number of lakes of size ii.

Examples2

  1. Example 1

    Input
    3 4
    ....
    .#..
    ###.
    
    Expected output
    4 1 0
    8 1 0
    
  2. Example 2

    Input
    6 5
    .....
    .....
    .....
    ..#..
    .###.
    #####
    
    Expected output
    9 4 1 0 0 0
    21 10 3 0 0 0