Problem list
Log in
#usaco0129 · USACO 2013-2014 January Gold

Building a Ski Course

Platinum III 2.0 s 256 MB

Farmer John is helping to turn his large field into a ski course for the upcoming winter Moolympics. The field has dimensions M x N (1 <= M,N <= 100), and its intended final composition is described by an M x N grid of characters, each 'R' for 'rough' or 'S' for 'smooth'.

To build the desired course, Farmer John plans to modify his tractor so that it can stamp any B x B patch of the field (B <= M, B <= N) with either entirely smooth snow or entirely rough snow. Since it takes a long time to reset the tractor between stamps, FJ wants to make B as large as possible. With B = 1 he can clearly create the desired course. However, for larger values of B, it may no longer be possible. Every unit square of the course must at some point be stamped; it cannot be left in its default state.

Please help FJ determine the largest possible value of B he can successfully use.

Input

  • Line 1: Two space-separated integers M and N.
  • Lines 2..M+1: M lines of exactly N characters (each R or S), describing the desired ski course design.

Output

The maximum value of B Farmer John can use to create the desired course pattern.

Example 1

Input
3 6
RSRSSS
RSRSSS
RSRSSS
Output
3

Output details: FJ can stamp overlapping 3x3 patches (rough cols 1-3, smooth 2-4, rough 3-5, smooth 4-6).

Source
USACO 2013-2014 January Gold
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code