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 NN consisting of unit squares of size 11. 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 aij (1aij106) minutes, where (i,j) 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 (1,1). Your task is to help Marichka maximize this score. Marichka is limited in time, so she can't spend more than T minutes exploring the grid.

Input format

The first line contains two integers N,T (1N150,1T109) --- size of the grid.
Each line i of the N subsequent lines (where 1iN) contains N integers describing i-th row of the grid --- ai1,ai2,...,ain.

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 22=4

Editor Image

?