#P8472. Divine Neatness
Divine Neatness
Divine Neatness
In the "Gulu Forum", a post has several replies which form an ( n \times m ) matrix. Each commenter's name appears in one of three colors: grey (G), purple (P) and brown (B). The forum administrator prAB wishes to improve the neatness of the comments by applying divine powers. However, he can use at most ( k ) divine operations because the forum owner may demote him if he abuses his power.
There are two types of divine operations available:
- Tyrannical Warning: Turn a grey name into a brown name.
- Let-off-the-hook: Unfreeze a brown name so that it becomes grey.
Note that purple names are untouchable.
prAB defines the neatness of the comments as the size (i.e. area) of the largest submatrix (i.e. a contiguous block of rows and columns) that can be made to have the same color after performing at most ( k ) operations. When converting, the following rules apply:
- To achieve a uniform grey submatrix, only grey and brown cells may be included. Every brown cell in the submatrix can be flipped (at a cost of 1 per cell) to grey. Purple cells are not allowed.
- Similarly, to achieve a uniform brown submatrix, only brown and grey cells may be included. Every grey cell can be flipped (cost 1) to brown. Purple cells are not allowed.
- For a purple submatrix, every cell must originally be purple (since no operation can change another color to purple).
Your task is to compute the maximum neatness after using at most ( k ) operations.
Input and Output Formats: See below.
inputFormat
The first line contains three integers ( n ), ( m ) and ( k ) where ( 1 \leq n,m \leq 300 ) and ( k \ge 0 ). Each of the next ( n ) lines contains a string of length ( m ) consisting only of the characters 'G', 'B', and 'P', representing grey, brown, and purple respectively.
outputFormat
Output a single integer representing the maximum area of a submatrix that can be made uniform (all cells of the same color) after performing at most ( k ) operations.
sample
3 3 1
GGG
GBG
GPG
6