#P9908. Find the Largest Snowflake

    ID: 23053 Type: Default 1000ms 256MiB

Find the Largest Snowflake

Find the Largest Snowflake

Lana loves drawing snowflakes. A snowflake of size \(x\) is defined as follows:

  • The center is a +.
  • There are exactly \(x\) | characters immediately above and below the center.
  • There are exactly \(x\) - characters immediately to the left and right of the center.
  • There are exactly \(x\) \\ characters along the top-left and bottom-right diagonals from the center.
  • There are exactly \(x\) / characters along the bottom-left and top-right diagonals from the center.

Snowflakes may overlap. Given an \(n \times m\) grid of characters, your task is to find the largest snowflake size present in the matrix. A snowflake is considered valid only if all required characters for a complete snowflake of that size are present in the proper positions. If no complete snowflake is found, output 0.

inputFormat

The first line contains two integers \(n\) and \(m\) (the number of rows and columns). The following \(n\) lines each contain a string of \(m\) characters representing the matrix.

outputFormat

Output a single integer: the size of the largest complete snowflake found in the grid. If none is found, output 0.

sample

1 1
+
0