F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Searchlights

Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 327680/327680 K (Java/Others)
Total Submission(s): 996    Accepted Submission(s): 255


Problem Description
There is a piece of grids land of size n¡Ám. Chandler and his team take responsibility to guard it. There are some searchlights on some pieces and each of them has a capability to lighten a distance towards four directions: north, south, east and west. Different searchlight has different lightening capability shown in levels. Searchlight with level k means that it can lighten k grids (including the gird that the searchlight stands in) along any of the four directions. Shown in following figure, there is a searchlight of level 3 and the shadow grids are ones that can be lightened by it. Particularly, searchlight of level 1 means that it can only lighten the grid in which the searchlight stands.

Each searchlight has a maximum level. You can decrease a searchlight¡¯s level to save the energy. A searchlight whose maximum level is k can be turned to level k, k-1, k-2, ¡­, 1 and 0. Level 0 means turning off the searchlight.

A grid is well-guarded if and only if at least one of the following two conditions is satisfied:
1.There is a searchlight in this grid, and it is not switched to level 0 (the light is on).
2.The grid is lightened by at least two searchlights. One lightens it in horizontal direction (east or west), and another lightens it in vertical direction (north or south).

Chandler asks you to help finding a solution that he can turn on some of the searchlights so that:
1.All the grids are well-guarded.
2.All the searchlights turned on are in a same level.
3.That same level mentioned above is as small as possible.
More specifically, if you choose a same level Q, then all the searchlights whose maximum level are less than Q have to be turned off. Please help him to find a solution with the minimum same level.
 

Input
The input file contains several test cases.

For each test case, the first line is two integers n and m, representing a grids land of size n¡Ám. (0<n<=100, 0<m<=10000). Following n lines describe an n¡Ám matrix in which ai,j means the maximum level of the searchlight in grid (i, j). ai,j can be zero, which means there is no searchlight on that grid. For all the cases, ai, j<=10000.

The input file ends with a line containing two zeros.
 

Output
For each test case, output a single line with an integer, representing the minimum level you have found. If there is no such a solution, output ¡°NO ANSWER!¡±
 

Sample Input
2 2 0 2 3 0 2 2 0 2 1 0 0 0
 

Sample Output
2 NO ANSWER!
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 12:08:49, Gzip enabled