Dividing a Rectangle into Three
Time limit2sMemory limit128 MB
Split a digit grid into three non-overlapping rectangles covering all cells and maximize the product of their digit sums.
- Level
Medium5 of 10
- Topics
- Prefix sum, Brute force, Matrix, Implementation
- Solved
- No attempts yet
Problem
An rectangle is filled with digits.
Divide the rectangle into three non-overlapping smaller rectangles. Every cell must belong to exactly one smaller rectangle, and each smaller rectangle must contain at least one cell.
The sum of a smaller rectangle is the sum of the digits inside it. Find the maximum possible product of the three sums after dividing the given rectangle into three smaller rectangles.
Input
The first line contains the rectangle height and width .
The next lines describe the rectangle from top to bottom. Each line contains exactly digits.
and are positive integers at most . The rectangle contains at least three cells. Each cell contains one decimal digit.
Output
Print the maximum possible product of the sums of the three smaller rectangles.