← 返回 bytedance 的题目列表Number of Islands and Number of Distinct Islands
类型:online_judge
Problem: Number of Islands and Number of Distinct Islands
Given an m x n 2D grid grid, where:
'1' represents land
'0' represents water
An island is formed by horizontally or vertically adjacent land cells. Complete the following two tasks:
Return the total number of islands in the grid.
Return the number of distinct island shapes.
Two islands are considered the same shape if and only if one can be translated to match the other exactly. Rotation or reflection does not count as the same shape.
Input Format
The first line contains two integers m and n.
The next m lines each contain a binary string of length n representing the grid.
Output Format
Print two integers:
total_number_of_islands number_of_distinct_islands
Constraints
1 <= m, n <= 500
grid[i][j] is either '0' or '1'
Example
Input:
4 5
11110
11010
11000
00000
Output:
1 1
Example
Input
4 5
11110
11010
11000
00000
Output
1 1