Travel diaries
Practice
0 (0 votes)
Grammar Verified
Open
Grammar Verified
Open
Graph theory
Breadth First search
Graph
Queue
Medium
Algorithms
Grammar Verified
Problem
83% Success 80 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code
You are given a matrix of size \(N \times M\) that contains the digits 0, 1, or 2 only. All the cells that contain 1 and are adjacent to any cell that contains 2 will be converted from 1 to 2, simultaneously in 1 second. Write a program to find the minimum time to convert all the cells having value 1 to 2.
Input format
- First line: Two space-separated integers N and M
- Next N lines: M space-separated integers (denoting the matrix)
Output format
Print the minimum time to convert all the cells having value 1 to 2.
Constraints
\(1 ≤ N, M ≤ 10^3 \)
Submissions
Please login to view your submissions
Similar Problems
Points:30
5 votes
Tags:
CombinatoricsDynamic ProgrammingEasy
Points:30
Tags:
OpenOpenOpenMath BasicBasic MathEasyMathematicsMath
Points:20
2 votes
Tags:
EasyMath
Editorial