102741: [AtCoder]ABC274 B - Line Sensor

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

Description

Score : $200$ points

Problem Statement

There is a grid with $H$ rows from top to bottom and $W$ columns from left to right. Let $(i, j)$ denote the square at the $i$-th row from the top and $j$-th column from the left.
The squares are described by characters $C_{i,j}$. If $C_{i,j}$ is ., $(i, j)$ is empty; if it is #, $(i, j)$ contains a box.

For integers $j$ satisfying $1 \leq j \leq W$, let the integer $X_j$ defined as follows.

  • $X_j$ is the number of boxes in the $j$-th column. In other words, $X_j$ is the number of integers $i$ such that $C_{i,j}$ is #.

Find all of $X_1, X_2, \dots, X_W$.

Constraints

  • $1 \leq H \leq 1000$
  • $1 \leq W \leq 1000$
  • $H$ and $W$ are integers.
  • $C_{i, j}$ is . or #.

Input

The input is given from Standard Input in the following format:

$H$ $W$
$C_{1,1}C_{1,2}\dots C_{1,W}$
$C_{2,1}C_{2,2}\dots C_{2,W}$
$\vdots$
$C_{H,1}C_{H,2}\dots C_{H,W}$

Output

Print $X_1, X_2, \dots, X_W$ in the following format:

$X_1$ $X_2$ $\dots$ $X_W$

Sample Input 1

3 4
#..#
.#.#
.#.#

Sample Output 1

1 2 0 3

In the $1$-st column, one square, $(1, 1)$, contains a box. Thus, $X_1 = 1$.
In the $2$-nd column, two squares, $(2, 2)$ and $(3, 2)$, contain a box. Thus, $X_2 = 2$.
In the $3$-rd column, no squares contain a box. Thus, $X_3 = 0$.
In the $4$-th column, three squares, $(1, 4)$, $(2, 4)$, and $(3, 4)$, contain a box. Thus, $X_4 = 3$.
Therefore, the answer is $(X_1, X_2, X_3, X_4) = (1, 2, 0, 3)$.


Sample Input 2

3 7
.......
.......
.......

Sample Output 2

0 0 0 0 0 0 0

There may be no square that contains a box.


Sample Input 3

8 3
.#.
###
.#.
.#.
.##
..#
##.
.##

Sample Output 3

2 7 4

Sample Input 4

5 47
.#..#..#####..#...#..#####..#...#...###...#####
.#.#...#.......#.#...#......##..#..#...#..#....
.##....#####....#....#####..#.#.#..#......#####
.#.#...#........#....#......#..##..#...#..#....
.#..#..#####....#....#####..#...#...###...#####

Sample Output 4

0 5 1 2 2 0 0 5 3 3 3 3 0 0 1 1 3 1 1 0 0 5 3 3 3 3 0 0 5 1 1 1 5 0 0 3 2 2 2 2 0 0 5 3 3 3 3

Input

题意翻译

一个 $H\times W$ 的矩阵,输出每一列字符`#`的个数。

Output

分数:$200$分

问题描述

有一个从上到下有$H$行、从左到右有$W$列的网格。让$(i, j)$表示从上数第$i$行、从左数第$j$列的方格。

方格用字符$C_{i,j}$描述。如果$C_{i,j}$是.,那么$(i, j)$是空的;如果它是#,那么$(i, j)$包含一个箱子。

对于满足$1 \leq j \leq W$的整数$j$,定义整数$X_j$如下。

  • $X_j$是第$j$列中的箱子数量。换句话说,$X_j$是满足$C_{i,j}$是#的整数$i$的数量。

找出所有的$X_1, X_2, \dots, X_W$。

约束

  • $1 \leq H \leq 1000$
  • $1 \leq W \leq 1000$
  • $H$和$W$是整数。
  • $C_{i, j}$是.#

输入

输入从标准输入按以下格式给出:

$H$ $W$
$C_{1,1}C_{1,2}\dots C_{1,W}$
$C_{2,1}C_{2,2}\dots C_{2,W}$
$\vdots$
$C_{H,1}C_{H,2}\dots C_{H,W}$

输出

按以下格式输出$X_1, X_2, \dots, X_W$:

$X_1$ $X_2$ $\dots$ $X_W$

样例输入1

3 4
#..#
.#.#
.#.#

样例输出1

1 2 0 3

在第$1$列中,有一个方格$(1, 1)$包含一个箱子。因此,$X_1 = 1$。

在第$2$列中,有两个方格$(2, 2)$和$(3, 2)$包含一个箱子。因此,$X_2 = 2$。

在第$3$列中,没有方格包含一个箱子。因此,$X_3 = 0$。

在第$4$列中,有三个方格$(1, 4)$、$(2, 4)$和$(3, 4)$包含一个箱子。因此,$X_4 = 3$。

因此,答案是$(X_1, X_2, X_3, X_4) = (1, 2, 0, 3)$。


样例输入2

3 7
.......
.......
.......

样例输出2

0 0 0 0 0 0 0

可能没有任何包含箱子的方格。


样例输入3

8 3
.#.
###

加入题单

算法标签: