#C5284. Rectangular Path Check
Rectangular Path Check
Rectangular Path Check
You are given a grid of n rows and m columns, where each cell contains either '1' or '0'. Your task is to determine whether there exists a rectangle in the grid such that all four corners of the rectangle are '1'.
A rectangle is defined by two distinct rows r1 and r2 (with r1 < r2) and two distinct columns c1 and c2 (with c1 < c2). The rectangle's corners are located at positions (r1, c1), (r1, c2), (r2, c1) and (r2, c2). The answer is "Yes" if such a rectangle exists, otherwise "No".
In mathematical terms, you need to check if there exist indices r1, r2, c1, c2 such that:
$$\text{grid}[r_1][c_1] = \text{grid}[r_1][c_2] = \text{grid}[r_2][c_1] = \text{grid}[r_2][c_2] = '1' $$inputFormat
The first line contains two integers n and m, separated by a space — the number of rows and columns in the grid.
Each of the next n lines contains a string of length m composed of characters '0' and '1', representing a row of the grid.
outputFormat
Output a single line containing either "Yes" if there exists a rectangle whose four corners are all '1', or "No" otherwise.
## sample4 5
11011
11011
11111
01110
Yes