Maximum Area

4.1

15 votes
Algorithms, Graphs, Medium, Shortest Path Algorithm
Problem

While walking around Hackerland, Marichka found a large square grid of size consisting of unit squares of size . Now Marichka wants to explore it as much as possible.

In one move Marichka can move to the cell which shares an edge with cell, where Marichka currently is. It will take her () minutes, where is the coordinates of the cell where Marichka moved. Marichka defines her exploration level as the maximum row number for all cells she visited multiplied by maximum column number for all cells she visited. Marichka always starts her exploration in the cell with coordinates . Your task is to help Marichka maximize this score. Marichka is limited in time, so she can't spend more than minutes exploring the grid.

Input format

The first line contains two integers () --- size of the grid.
Each line of the subsequent lines (where ) contains  integers describing -th row of the grid --- .

Output format

Output maximum Marichka's exploration level.

 

Sample Input
3 18
4 7 11
7 100 100
100 100 100
Sample Output
4
Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

Marichka can move to the cell (1,2) in time 7, then to the cell (1,1) in time 4, then to the cell (2,1) in time 7. The maximum column number will be 2, the maximum row number will be 2, so answer in such case will be

Editor Image

?