#P4330. Square Killers in Memory

    ID: 17576 Type: Default 1000ms 256MiB

Square Killers in Memory

Square Killers in Memory

Mirko suspects that a bug in his program might be caused by the presence of square killers in the program memory. The memory is represented as a matrix with R rows and C columns containing only 0s and 1s. A square killer is defined as a square submatrix (with size at least 2) that looks exactly the same when rotated 180°. In other words, a square submatrix of size \( k \) (with \( k \ge 2 \)) starting at \( (i,j) \) is a killer if it satisfies

$$A[i+u][j+v] = A[i + k - 1 - u][j + k - 1 - v] \quad \text{for all } 0 \le u,v \le k-1. $$

Your task is to determine the size of the largest square killer in the memory. If there is no square killer, output -1.

inputFormat

The first line contains two space-separated integers \( R \) and \( C \) — the number of rows and columns of the matrix.

Each of the next \( R \) lines contains a string of length \( C \) representing a row of the matrix. Each character is either '0' or '1'.

outputFormat

Output a single integer — the size (i.e. the number of rows or columns) of the largest square killer. If no square killer exists, output -1.

sample

2 2
10
01
2