P14567 [HackerRank] Demidenko farmer
提高
题目描述

The farmer decided to build a barn on his farm. But on his farm there are trees and other buildings, which he does not want to remove.

For simplicity, we represent the farm as a rectangular grid of height $N$ and width ${M}$. Each of the trees and buildings are located in one or more cells of the grid. The barn is a rectangle and should be built on the free cells of the grid.

Help the farmer to find out how many ways there are to place the barn, for all possible sizes of barns.

Input Format

The first line contains two integers $N$ and ${M}$ - the dimensions of the farm.

The next $N$ lines contains description of the farm: each line contains ${M}$ characters - 0 or 1 (1 means the cell is available/free for building the barn).

Output Format

Write $N$ lines with ${M}$ integers in each line. The $j^{th}$ value in the $i^{th}$ line must be equal to the number of ways to place a barn with height ${i}$ and width $j$ in the farm.

Constraints

$1\leq N,M\leq1024$

Sample input

3 3
011
110
110

Sample Output

6 3 0
3 1 0
1 0 0

Explanation

Barns with height 1 and width 1:

01 01 011 011 011 011
110 110 10 10 110 110
110 110 110 110 10 10

Barns with height 1 and width 2:

0 011 011
110
0 110
110 110 **0

Barns with height 2 and width 1:

01 011 011
1
0 10 10
110 10 10

Barns with height 2 and width 2 (there is only one):

011
0
0

Barns with height 3 and width 1 (there is only one):

01
1
0
1*0

Time Limits: C/C++ 1 sec, Java/C# 2 sec, other languages follow standard TL given in Environment

输入格式

见题面

输出格式

见题面

样例输入
3 3 011 110 110
样例输出
6 3 0 3 1 0 1 0 0