A11440 | Binary Matrix
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given a matrix of size $n×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!
Note that the memory limit is unusual!
输入格式
The first line contains two numbers $n$ and $m$ ( $1<=n<=2^{12}$ , $4<=m<=2^{14}$ ) — the number of rows and columns, respectively. It is guaranteed that $m$ is divisible by 4.
Then the representation of matrix follows. Each of $n$ next lines contains  one-digit hexadecimal numbers (that is, these numbers can be represented either as digits from $0$ to $9$ or as uppercase Latin letters from $A$ to $F$ ). Binary representation of each of these numbers denotes next $4$ elements of the matrix in the corresponding row. For example, if the number $B$ is given, then the corresponding elements are 1011, and if the number is $5$ , then the corresponding elements are 0101.
Elements are not separated by whitespaces.
Then the representation of matrix follows. Each of $n$ next lines contains  one-digit hexadecimal numbers (that is, these numbers can be represented either as digits from $0$ to $9$ or as uppercase Latin letters from $A$ to $F$ ). Binary representation of each of these numbers denotes next $4$ elements of the matrix in the corresponding row. For example, if the number $B$ is given, then the corresponding elements are 1011, and if the number is $5$ , 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:
The second example:
There are no 1's in the third example, so the answer is 0.
<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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted