CF884E.Binary Matrix

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

You are given a matrix of size n×mn×m . Each element of the matrix is either 1 or 0. You have to determine the number of connected components consisting of 1's. Two cells belong to the same component if they have a common border, and both elements in these cells are 1's.

Note that the memory limit is unusual!

输入格式

The first line contains two numbers nn and mm ( 1<=n<=2121<=n<=2^{12} , 4<=m<=2144<=m<=2^{14} ) — the number of rows and columns, respectively. It is guaranteed that mm is divisible by 4.

Then the representation of matrix follows. Each of nn next lines contains one-digit hexadecimal numbers (that is, these numbers can be represented either as digits from 00 to 99 or as uppercase Latin letters from AA to FF ). Binary representation of each of these numbers denotes next 44 elements of the matrix in the corresponding row. For example, if the number BB is given, then the corresponding elements are 1011, and if the number is 55 , then the corresponding elements are 0101.

Elements are not separated by whitespaces.

输出格式

Print the number of connected components consisting of 1's.

输入输出样例

  • 输入#1

    3 4
    1
    A
    8
    

    输出#1

    3
    
  • 输入#2

    2 8
    5F
    E3
    

    输出#2

    2
    
  • 输入#3

    1 4
    0
    

    输出#3

    0
    

说明/提示

In the first example the matrix is:

<br></br>0001<br></br>1010<br></br>1000<br></br>It is clear that it has three components.

The second example:

<br></br>01011111<br></br>11100011<br></br>It is clear that the number of components is 2.

There are no 1's in the third example, so the answer is 0.

首页