#C1003. Largest Square in a Matrix
Largest Square in a Matrix
Largest Square in a Matrix
You are given a matrix of characters with dimensions \(r \times c\). Each cell of the matrix contains either '0' or '1'. Your task is to find the area of the largest square sub-matrix that contains only '1's.
For example, given the matrix:
1 0 1 0 0 1 0 1 1 1 1 1 1 1 1 1 0 0 1 0
The largest square containing only '1's has a side length of 2, and its area is \(2^2 = 4\).
The formula to compute the area of a square is given by: \(\text{Area} = \text{side}^2\).
inputFormat
The first line contains two integers (r) and (c), representing the number of rows and columns in the matrix. Each of the following (r) lines contains (c) space-separated characters (each being either '0' or '1').
outputFormat
Output a single integer, the area of the largest square that contains only '1's.## sample
4 5
1 0 1 0 0
1 0 1 1 1
1 1 1 1 1
1 0 0 1 0
4