Garden 2
Time limit4sMemory limit1024 MB
Given an N by N grid of R, Y, and B cells, find the largest diamond pattern where each concentric ring has one color and count its flowers.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Matrix, Implementation
- Solved
- No attempts yet
Problem
The JOI garden is a square grid of rows and columns. The cell in row (counting from the top) and column (counting from the left) is called cell .
The soil in the JOI garden is poor, so each cell can hold at most one flower of one color. Cell can hold a red flower if is R, a yellow flower if is Y, and a blue flower if is B.
To make the garden look good in aerial photos, the manager K plans to plant flowers with the following steps.
- Choose an integer for the size. It must satisfy .
- Choose a center cell . It must satisfy and .
- Choose colors , each one of red, yellow, or blue.
- For each cell , let , where is the absolute value of . Plant flowers as follows.
- If , plant a flower of color in cell .
- If , plant no flower in cell .
Given and the color information for each cell, find the maximum number of flowers the manager K can plant.
Input
The first line contains . Each of the next lines contains the values through for row .
Output
Print the maximum number of flowers that K can plant on one line.
Constraints
Each is R, Y, or B.
is an integer.