Islands


Submit solution

Points: 25
Time limit: 1.0s
Memory limit: 256M

Author:
Problem type

You will be given a 2D matrix filled with zeros and ones : Zeroes represent sea and ones represent soil.

A group of adjacent ones form an island, we want you to compute the number of them.

Cell \((i,j)\) is adjacent to cells \((x,y)\) iif \(|x-i| \leq 1\) and \(|y-j| \leq 1\)

Input Specification

The first line of the input file contains two integers \(n\) and \(m\) (\( 1 \leq n,m \leq 1000\)).

Then follows \(N\) strings, of size \(M\) each, consisting of zeros and ones.

Output Specification

Output one integer : the number of islands.

Sample Input

4 4
1100
1100
0000
0001

Sample Output

2

Comments

There are no comments at the moment.